public void write(Collection<SinkRecord> records) {
    for (SinkRecord sinkRecord : records) {
      final String indexOverride = topicToIndexMap.get(sinkRecord.topic());
      final String index = indexOverride != null ? indexOverride : sinkRecord.topic();
      final boolean ignoreKey = ignoreKeyTopics.contains(sinkRecord.topic()) || this.ignoreKey;
      final boolean ignoreSchema =
          ignoreSchemaTopics.contains(sinkRecord.topic()) || this.ignoreSchema;

      if (!ignoreSchema && !existingMappings.contains(index)) {
        try {
          if (Mapping.getMapping(client, index, type) == null) {
            Mapping.createMapping(client, index, type, sinkRecord.valueSchema());
          }
        } catch (IOException e) {
          // FIXME: concurrent tasks could attempt to create the mapping and one of the requests may
          // fail
          throw new ConnectException("Failed to initialize mapping for index: " + index, e);
        }
        existingMappings.add(index);
      }

      final IndexableRecord indexableRecord =
          DataConverter.convertRecord(sinkRecord, index, type, ignoreKey, ignoreSchema);

      bulkProcessor.add(indexableRecord, flushTimeoutMs);
    }
  }
  /**
   * Get the animated sprite for an indexed tile of a tileset.
   *
   * @param tileset The tileset to load from.
   * @param index The index with-in the tileset.
   * @return A sprite, or <code>null</code> if no mapped sprite.
   */
  public Sprite getSprite(final Tileset tileset, final int index) {
    final Mapping mapping = animations.get(Integer.valueOf(index));

    if (mapping == null) {
      return null;
    }

    final int[] frameIndexes = mapping.getIndices();
    final int[] frameDelays = mapping.getDelays();

    final Sprite[] frames = new Sprite[frameIndexes.length];

    for (int i = 0; i < frameIndexes.length; i++) {
      frames[i] = tileset.getSprite(frameIndexes[i]);
    }

    // Use the reference of the first frame as the reference for the whole
    // group
    Object ref = null;
    Sprite first = frames[0];
    if (first != null) {
      ref = first.getReference();
    }
    return new AnimatedSprite(frames, frameDelays, true, ref);
  }
  /**
   * Processes trigger mappings.
   *
   * @param mapping The mapping value.
   * @param axisNo The number of the analog axis.
   */
  private void processTriggerAxis(String mapping, int axisNo, int triggerNo) {
    TriggerID mappedID = TriggerID.getTriggerIDfromString(mapping);
    if (mappedID != null) {
      if (Log.debugEnabled) {
        Log.logger.debug(
            "Map axis no. " + axisNo + " from mapping " + mapping + " to trigger " + mappedID);
      }
      this.axes[axisNo] = new BaseAxis(AxisID.TRIGGER, axisNo);

      // TODO: SET LABELS AND RESOURCE KEYS

      this.triggers[triggerNo] = new BaseTrigger(this, triggerNo, this.axes[axisNo], "", "");
      this.triggers[triggerNo].setID(mappedID);

      this.triggerMap.put(mappedID, this.triggers[triggerNo]);
      String label = Mapping.getTriggerLabel(this, mappedID);
      if (label == null) {
        label = Mapping.getDefaultTriggerLabel(mappedID);
      }
      if (label != null) {
        this.triggers[triggerNo].setDefaultLabel(label);
      }
      String labelKey = Mapping.getTriggerLabelKey(this, mappedID);
      if (labelKey != null) {
        this.triggers[triggerNo].setLabelKey(labelKey);
      }
    }
  }
Beispiel #4
0
 public synchronized Nomin parse(Mapping mapping) {
   cachedApplicable.clear(); // the cache is cleared before parsing a mapping
   mapping.setMapper(this);
   mapping.introspector(defaultIntrospector);
   addOrReplace(mapping.parse());
   return this;
 }
Beispiel #5
0
  @Test
  public void shouldBeSerializable() {
    Mapping mapping = new Mapping();
    mapping.setProcessorMethod("setChannelRecording");
    mapping.setProcessorMethodArguments(new LinkedList<>());
    mapping
        .getProcessorMethodArguments()
        .add(new MappingMethodArgument("channelId", Long.class.getName()));
    mapping
        .getProcessorMethodArguments()
        .add(new MappingMethodArgument("recording", Boolean.class.getName()));
    mapping.setTriggerValueMap(new HashMap<>());
    mapping.getTriggerValueMap().put("command", 1);
    mapping.getTriggerValueMap().put("channel", 2);
    mapping.getTriggerValueMap().put("data1", 3);
    mapping.getTriggerValueMap().put("data2", 4);
    mapping.setValueExpressionMap(new HashMap<>());
    mapping.getValueExpressionMap().put("channelId", "#{data1} * 10");
    mapping.getValueExpressionMap().put("recording", "#{data2} == 4");

    String json = new Gson().toJson(mapping);

    JsonAssert.with(json)
        .assertThat("processorMethod", is("setChannelRecording"))
        .assertThat("processorMethodArguments[0].name", is("channelId"))
        .assertThat("processorMethodArguments[0].type", is("java.lang.Long"))
        .assertThat("processorMethodArguments[1].name", is("recording"))
        .assertThat("processorMethodArguments[1].type", is("java.lang.Boolean"))
        .assertThat("triggerValueMap.command", is(1))
        .assertThat("triggerValueMap.channel", is(2))
        .assertThat("triggerValueMap.data1", is(3))
        .assertThat("triggerValueMap.data2", is(4))
        .assertThat("valueExpressionMap.channelId", is("#{data1} * 10"))
        .assertThat("valueExpressionMap.recording", is("#{data2} == 4"));
  }
Beispiel #6
0
  /** Variant of {@link #trimFields(RelNode, BitSet, Set)} for {@link TableModificationRel}. */
  public TrimResult trimFields(
      TableModificationRel modifier, BitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
    // Ignore what consumer wants. We always project all columns.
    Util.discard(fieldsUsed);

    final RelDataType rowType = modifier.getRowType();
    final int fieldCount = rowType.getFieldCount();
    RelNode input = modifier.getChild();

    // We want all fields from the child.
    final int inputFieldCount = input.getRowType().getFieldCount();
    BitSet inputFieldsUsed = Util.bitSetBetween(0, inputFieldCount);

    // Create input with trimmed columns.
    final Set<RelDataTypeField> inputExtraFields = Collections.emptySet();
    TrimResult trimResult = trimChild(modifier, input, inputFieldsUsed, inputExtraFields);
    RelNode newInput = trimResult.left;
    final Mapping inputMapping = trimResult.right;
    if (!inputMapping.isIdentity()) {
      // We asked for all fields. Can't believe that the child decided
      // to permute them!
      throw Util.newInternal("Expected identity mapping, got " + inputMapping);
    }

    TableModificationRel newModifier = modifier;
    if (newInput != input) {
      newModifier = modifier.copy(modifier.getTraitSet(), Collections.singletonList(newInput));
    }
    assert newModifier.getClass() == modifier.getClass();

    // Always project all fields.
    Mapping mapping = Mappings.createIdentity(fieldCount);
    return new TrimResult(newModifier, mapping);
  }
Beispiel #7
0
 /* (non-Javadoc)
  * @see org.openrdf.rio.helpers.RDFHandlerBase#handleStatement(org.openrdf.model.Statement)
  */
 @Override
 public void handleStatement(final Statement stmt) throws RDFHandlerException {
   final String predicate = stmt.getPredicate().stringValue();
   if (!predicate.startsWith("http://psi.ontopia.net/rdf2tm/#")) {
     return;
   }
   final String subject = stmt.getSubject().stringValue();
   if (!(stmt.getObject() instanceof URI)) {
     throw new RDFHandlerException(
         new MIOException("The object of the RDF mapping must be an IRI"));
   }
   final String object = stmt.getObject().stringValue();
   if (RDF2TM.MAPS_TO.equals(predicate)) {
     if (RDF2TM.BASENAME.equals(object)) {
       getMapping(subject).kind = NAME;
     } else if (RDF2TM.OCCURRENCE.equals(object)) {
       getMapping(subject).kind = OCCURRENCE;
     } else if (RDF2TM.INSTANCE_OF.equals(object)) {
       getMapping(subject).kind = TYPE_INSTANCE;
     } else if (RDF2TM.ASSOCIATION.equals(object)) {
       getMapping(subject).kind = ASSOCIATION;
     } else if (RDF2TM.SUBJECT_IDENTIFIER.equals(object)) {
       try {
         _handler.handleSubjectIdentifier(subject);
       } catch (MIOException ex) {
         throw new RDFHandlerException(ex);
       }
     } else if (RDF2TM.SUBJECT_LOCATOR.equals(object)) {
       try {
         _handler.handleSubjectLocator(subject);
       } catch (MIOException ex) {
         throw new RDFHandlerException(ex);
       }
     } else if (RDF2TM.SOURCE_LOCATOR.equals(object)) {
       try {
         _handler.handleItemIdentifier(subject);
       } catch (MIOException ex) {
         throw new RDFHandlerException(ex);
       }
     } else {
       throw new RDFHandlerException(
           new MIOException(
               "Unknown object of a rtm:maps-to mapping. Object: <" + object + ">"));
     }
   } else if (RDF2TM.TYPE.equals(predicate)) {
     getMapping(subject).type = object;
   } else if (RDF2TM.IN_SCOPE.equals(predicate)) {
     Mapping mapping = getMapping(subject);
     if (mapping.scope == null) {
       mapping.scope = new ArrayList<String>();
     }
     mapping.scope.add(object);
   } else if (RDF2TM.SUBJECT_ROLE.equals(predicate)) {
     getMapping(subject).subject = object;
   } else if (RDF2TM.OBJECT_ROLE.equals(predicate)) {
     getMapping(subject).object = object;
   } else {
     throw new RDFHandlerException(new MIOException("Unknown predicate <" + predicate + ">"));
   }
 }
Beispiel #8
0
  /** Variant of {@link #trimFields(RelNode, BitSet, Set)} for {@link SortRel}. */
  public TrimResult trimFields(SortRel sort, BitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
    final RelDataType rowType = sort.getRowType();
    final int fieldCount = rowType.getFieldCount();
    final RelCollation collation = sort.getCollation();
    final RelNode input = sort.getChild();

    // We use the fields used by the consumer, plus any fields used as sort
    // keys.
    BitSet inputFieldsUsed = (BitSet) fieldsUsed.clone();
    for (RelFieldCollation field : collation.getFieldCollations()) {
      inputFieldsUsed.set(field.getFieldIndex());
    }

    // Create input with trimmed columns.
    final Set<RelDataTypeField> inputExtraFields = Collections.emptySet();
    TrimResult trimResult = trimChild(sort, input, inputFieldsUsed, inputExtraFields);
    RelNode newInput = trimResult.left;
    final Mapping inputMapping = trimResult.right;

    // If the input is unchanged, and we need to project all columns,
    // there's nothing we can do.
    if (newInput == input && inputMapping.isIdentity() && fieldsUsed.cardinality() == fieldCount) {
      return new TrimResult(sort, Mappings.createIdentity(fieldCount));
    }

    final SortRel newSort =
        sort.copy(sort.getTraitSet(), newInput, RexUtil.apply(inputMapping, collation));
    assert newSort.getClass() == sort.getClass();

    // The result has the same mapping as the input gave us. Sometimes we
    // return fields that the consumer didn't ask for, because the filter
    // needs them for its condition.
    return new TrimResult(newSort, inputMapping);
  }
Beispiel #9
0
    public SourceMethod build() {

      MappingOptions mappingOptions =
          new MappingOptions(mappings, iterableMapping, mapMapping, beanMapping, valueMappings);

      SourceMethod sourceMethod =
          new SourceMethod(
              declaringMapper,
              executable,
              parameters,
              returnType,
              exceptionTypes,
              mappingOptions,
              typeUtils,
              typeFactory,
              mapperConfig,
              prototypeMethods,
              definingType);

      if (mappings != null) {
        for (Map.Entry<String, List<Mapping>> entry : mappings.entrySet()) {
          for (Mapping mapping : entry.getValue()) {
            mapping.init(sourceMethod, messager, typeFactory, false);
          }
        }
      }
      return sourceMethod;
    }
Beispiel #10
0
  /**
   * Returns the {@link Mapping}s for the given source property.
   *
   * @param sourcePropertyName the source property name
   * @return list of mappings
   */
  public List<Mapping> getMappingBySourcePropertyName(String sourcePropertyName) {
    List<Mapping> mappingsOfSourceProperty = new ArrayList<Mapping>();

    for (List<Mapping> mappingOfProperty : mappingOptions.getMappings().values()) {
      for (Mapping mapping : mappingOfProperty) {

        if (isEnumMapping()) {
          if (mapping.getSourceName().equals(sourcePropertyName)) {
            mappingsOfSourceProperty.add(mapping);
          }
        } else {
          List<PropertyEntry> sourceEntries = mapping.getSourceReference().getPropertyEntries();

          // there can only be a mapping if there's only one entry for a source property, so:
          // param.property.
          // There can be no mapping if there are more entries. So: param.property.property2
          if (sourceEntries.size() == 1
              && sourcePropertyName.equals(first(sourceEntries).getName())) {
            mappingsOfSourceProperty.add(mapping);
          }
        }
      }
    }

    return mappingsOfSourceProperty;
  }
  /** Overrides the default behaviour to including binding of Grails domain classes. */
  @Override
  protected void secondPassCompile() throws MappingException {
    if (configLocked) {
      return;
    }

    // set the class loader to load Groovy classes
    if (grailsApplication != null) {
      Thread.currentThread().setContextClassLoader(grailsApplication.getClassLoader());
    }

    configureDomainBinder(grailsApplication, domainClasses);

    for (GrailsDomainClass domainClass : domainClasses) {
      if (!GrailsHibernateUtil.usesDatasource(domainClass, dataSourceName)) {
        continue;
      }
      final Mappings mappings = super.createMappings();
      Mapping m = binder.getMapping(domainClass);
      mappings.setAutoImport(m == null || m.getAutoImport());
      binder.bindClass(domainClass, mappings, sessionFactoryBeanName);
    }

    super.secondPassCompile();
    configLocked = true;
  }
Beispiel #12
0
  /**
   * Gets the outputs.
   *
   * @param bundle the bundle
   * @return the outputs
   */
  public static HashMap<String, ConfigurationResource> getOutputs(File bundle) {

    HashMap<String, ConfigurationResource> results = new HashMap<String, ConfigurationResource>();
    try {
      //            SHIWABundle shiwaBundle = new SHIWABundle(bundle);

      ConcreteBundle concreteBundle = new ConcreteBundle(bundle);
      //            WorkflowController workflowController = new WorkflowController(shiwaBundle);

      for (Mapping configuration : concreteBundle.getPrimaryMappings()) {
        System.out.println("Config type : " + configuration.getClass().getCanonicalName());

        if (configuration instanceof ExecutionMapping) {
          System.out.println("Received bundle has an exec config");

          System.out.println(
              configuration.getAggregatedResources().size() + " aggregated resources");

          System.out.println(
              "Exec config contains " + configuration.getResources().size() + " resources.");
          for (ConfigurationResource r : configuration.getResources()) {
            results.put(r.getReferableResource().getTitle(), r);
          }
          System.out.println(results.size() + " outputs found.");
          return results;
        }
      }
    } catch (SHIWADesktopIOException e) {
      System.out.println("Returned bundle was corrupt or null.");
      ErrorTracker.getErrorTracker()
          .broadcastError(new ErrorEvent(null, e, "Returned Bundle was corrupt or null"));
    }

    return null;
  }
Beispiel #13
0
  public static void main(String[] args) {
    UPnPManager upnp = UPnPManager.getInstance();
    if (!upnp.start()) {
      System.out.println("Could not start UPnPManager.");
      return;
    }

    upnp.waitForDeviceFound();

    System.out.println("External IP address: " + upnp.getExternalAddress());

    Mapping map =
        new Mapping(
            3997, // external port
            "192.168.0.107", // internal IP address
            3997, // internal port
            Mapping.Protocol.UDP, // protocol: TCP or UDP
            null); // description (option)

    // adds a mapping
    if (upnp.addMapping(map)) System.out.println("succeeded.");
    else System.out.println("failed.");

    // deletes a mapping
    if (upnp.deleteMapping(map.getExternalPort(), map.getProtocol()))
      System.out.println("succeeded.");
    else System.out.println("failed.");

    upnp.stop();
  }
 public static List<String> getDatasourceNames(PersistentEntity domainClass) {
   final Entity mappedForm = domainClass.getMapping().getMappedForm();
   if (mappedForm instanceof Mapping) {
     Mapping mapping = (Mapping) mappedForm;
     return mapping.getDatasources();
   }
   return Collections.singletonList(Mapping.DEFAULT_DATA_SOURCE);
 }
 private void reportMappingError(Message msg, Object... objects) {
   messager.printMessage(
       method.getExecutable(),
       mapping.getMirror(),
       mapping.getSourceAnnotationValue(),
       msg,
       objects);
 }
 private Mapping partialMapping() {
   Mapping mapping = mock(Mapping.class);
   given(mapping.getOperationMessageAttibute()).willReturn(OPERATION_FIELD_NAME);
   given(mapping.getOperationForMethod("mappedCall")).willReturn("OP");
   given(mapping.getMethodForOperation("OP")).willReturn("mappedCall");
   givenFieldMapping(mapping, "s1", FieldMapping.map("a"));
   return new CheckedMapping(mapping);
 }
 public void testCyclicMapping() {
   Mapping<Integer, String> mapping = new Mapping<Integer, String>();
   assertEquals(mapping.f, mapping.getFromType());
   assertEquals(mapping.t, mapping.getToType());
   assertEquals(mapping.f, mapping.flip().getFromType());
   assertEquals(mapping.t, mapping.flip().getToType());
   assertEquals(mapping.f, mapping.selfMapping().getFromType());
   assertEquals(mapping.t, mapping.selfMapping().getToType());
 }
Beispiel #18
0
 private Mapping createMapping(BitSet fieldsUsed, int fieldCount) {
   final Mapping mapping =
       Mappings.create(MappingType.InverseSurjection, fieldCount, fieldsUsed.cardinality());
   int i = 0;
   for (int field : Util.toIter(fieldsUsed)) {
     mapping.set(field, i++);
   }
   return mapping;
 }
 /** Print an ontology term mapping created by LOOM. */
 private static void printLoomMapping(Mapping loomMap) {
   if (!mapSet.contains(loomMap.hashString())) {
     mapSet.add(loomMap.hashString());
     // if (oSerializeFormat.equals("turtle")) {
     oStream.print(loomMap.toTurtle(true));
     // }
     oMapCount++;
   }
 }
    @Override
    public IdentityMapping createIdentityMapping(final ClassMapping classMapping) {
      final Mapping mappedForm = createMappedForm(classMapping.getEntity());
      final Object identity = mappedForm.getIdentity();
      final ValueGenerator generator;
      if (identity instanceof Identity) {
        Identity id = (Identity) identity;
        String generatorName = id.getGenerator();
        if (generatorName != null) {
          try {
            generator = ValueGenerator.valueOf(generatorName.toUpperCase());
          } catch (IllegalArgumentException e) {
            throw new DatastoreConfigurationException(
                "Invalid id generation strategy for entity ["
                    + classMapping.getEntity().getName()
                    + "]: "
                    + generatorName);
          }
        } else {
          generator = ValueGenerator.AUTO;
        }
      } else {
        generator = ValueGenerator.AUTO;
      }
      return new IdentityMapping() {
        @Override
        public String[] getIdentifierName() {
          if (identity instanceof Identity) {
            final String name = ((Identity) identity).getName();
            if (name != null) {
              return new String[] {name};
            } else {
              return DEFAULT_IDENTITY_MAPPING;
            }
          } else if (identity instanceof CompositeIdentity) {
            return ((CompositeIdentity) identity).getPropertyNames();
          }
          return DEFAULT_IDENTITY_MAPPING;
        }

        @Override
        public ValueGenerator getGenerator() {

          return generator;
        }

        @Override
        public ClassMapping getClassMapping() {
          return classMapping;
        }

        @Override
        public Property getMappedForm() {
          return (Property) identity;
        }
      };
    }
 public ExtendedIterator<Domain> executeBindings(
     List<Stage> outStages, NamedGraphMap args, Node[] nodes) {
   Mapping map = new Mapping(nodes);
   ArrayList<Stage> stages = new ArrayList<Stage>();
   addStages(stages, args, map);
   if (constraint.isComplex()) stages.add(new ConstraintStage(map, constraint));
   outStages.addAll(stages);
   variableCount = map.size();
   return filter(connectStages(stages, variableCount));
 }
 @Override
 public Alignment rematch(Alignment a) {
   Alignment maps = new Alignment();
   for (Mapping m : a) {
     int sId = m.getSourceId();
     int tId = m.getTargetId();
     maps.add(sId, tId, mapTwoTerms(sId, tId));
   }
   return maps;
 }
Beispiel #23
0
 /**
  * Gets the configuration resource for dependency.
  *
  * @param dependency the dependency
  * @return the configuration resource for dependency
  */
 public ConfigurationResource getConfigurationResourceForDependency(Dependency dependency) {
   for (Mapping mapping : concreteBundle.getPrimaryMappings()) {
     for (ConfigurationResource configurationResource : mapping.getResources()) {
       if (dependency.getId().equals(configurationResource.getId())) {
         return configurationResource;
       }
     }
   }
   return null;
 }
Beispiel #24
0
  /**
   * Variant of {@link #trimFields(RelNode, BitSet, Set)} for {@link SetOpRel} (including UNION and
   * UNION ALL).
   */
  public TrimResult trimFields(
      SetOpRel setOp, BitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
    final RelDataType rowType = setOp.getRowType();
    final int fieldCount = rowType.getFieldCount();
    int changeCount = 0;

    // Fennel abhors an empty row type, so pretend that the parent rel
    // wants the last field. (The last field is the least likely to be a
    // system field.)
    if (fieldsUsed.isEmpty()) {
      fieldsUsed.set(rowType.getFieldCount() - 1);
    }

    // Compute the desired field mapping. Give the consumer the fields they
    // want, in the order that they appear in the bitset.
    final Mapping mapping = createMapping(fieldsUsed, fieldCount);

    // Create input with trimmed columns.
    final List<RelNode> newInputs = new ArrayList<RelNode>();
    for (RelNode input : setOp.getInputs()) {
      TrimResult trimResult = trimChild(setOp, input, fieldsUsed, extraFields);
      RelNode newInput = trimResult.left;
      final Mapping inputMapping = trimResult.right;

      // We want "mapping", the input gave us "inputMapping", compute
      // "remaining" mapping.
      //    |                   |                |
      //    |---------------- mapping ---------->|
      //    |-- inputMapping -->|                |
      //    |                   |-- remaining -->|
      //
      // For instance, suppose we have columns [a, b, c, d],
      // the consumer asked for mapping = [b, d],
      // and the transformed input has columns inputMapping = [d, a, b].
      // remaining will permute [b, d] to [d, a, b].
      Mapping remaining = Mappings.divide(mapping, inputMapping);

      // Create a projection; does nothing if remaining is identity.
      newInput = CalcRel.projectMapping(newInput, remaining, null);

      if (input != newInput) {
        ++changeCount;
      }
      newInputs.add(newInput);
    }

    // If the input is unchanged, and we need to project all columns,
    // there's to do.
    if (changeCount == 0 && mapping.isIdentity()) {
      return new TrimResult(setOp, mapping);
    }

    RelNode newSetOp = setOp.copy(setOp.getTraitSet(), newInputs);
    return new TrimResult(newSetOp, mapping);
  }
 @Test
 public void testApply() {
   AllocateEvent na = new AllocateEvent(vms.get(0), "foo", 3);
   Model mo = new DefaultModel();
   Mapping map = mo.getMapping();
   map.addOnlineNode(ns.get(0));
   map.addRunningVM(vms.get(0), ns.get(0));
   Assert.assertFalse(na.apply(mo));
   ShareableResource rc = new ShareableResource("foo");
   mo.attach(rc);
   Assert.assertTrue(na.apply(mo));
   Assert.assertEquals(3, rc.getConsumption(vms.get(0)));
 }
Beispiel #26
0
  /**
   * Gets the first configuration of type.
   *
   * @param mappingType the mapping type
   * @return the first configuration of type
   */
  private Mapping getFirstConfigurationOfType(Class<? extends Mapping> mappingType) {
    for (Mapping mapping : concreteBundle.getPrimaryMappings()) {

      if (mapping.getClass().isAssignableFrom(mappingType)) {
        return mapping;
      }

      //            if (config.getType() == configType) {
      //                return config;
      //            }
    }
    return null;
  }
  private void removeMapping(Shell shell) {
    TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
    TableItem[] itemsMappings = fMappingsTable.getSelection();

    if (itemsMappings.length > 0 && itemsIdMaps.length > 0) {
      Mapping mapping = (Mapping) itemsMappings[0].getData();
      IdMap idmap = (IdMap) itemsIdMaps[0].getData();
      HashMap idmapHS = (HashMap) fIdMaps.get(idmap.getName());
      idmapHS.remove(mapping.getKey());
      Vector mappings = idmap.getMappings();
      mappings.remove(mapping);
      itemsMappings[0].dispose(); // Table is single selection
    }
  }
  protected TableItem newOrderedTableItem(Mapping mapping, boolean selected) {
    TableItem[] items = fOrderedTable.getItems();
    int i = 0;
    while (i < items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0)
      i++;

    TableItem item = new TableItem(fOrderedTable, SWT.NULL, i);

    String[] values = new String[] {mapping.getElement(), mapping.getSignature()};
    item.setText(values);
    item.setData(mapping);
    if (selected) fOrderedTable.setSelection(i);

    return item;
  }
Beispiel #29
0
    @Override
    public Mapping clone() {
      Mapping copy;

      try {
        copy = (Mapping) super.clone();
      } catch (CloneNotSupportedException e) {
        throw new Error("");
      }

      copy.key = this.key;
      copy.value = this.value;

      return copy;
    }
 private void removeOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0 && itemsIdMaps.length > 0) {
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     idmapAL.remove(mapping.getKey());
     if (idmapAL.size() <= 0) fOrderedElements.remove(idmap.getName());
     ArrayList ordered = idmap.getOrdered();
     ordered.remove(mapping);
     if (ordered.size() <= 0) idmap.setOrdered(null);
     itemsOrdered[0].dispose(); // Table is single selection
   }
 }