private void verifyListChange() {
    this.event = null;
    this.eventType = null;
    this.listHolder.addItem(4, "E");
    this.verifyEvent(ADD, 7, "E");

    this.event = null;
    this.eventType = null;
    this.listHolder.addItem(5, null);
    this.verifyEvent(ADD, 8, null);

    this.event = null;
    this.eventType = null;
    this.listHolder.removeItem(5);
    this.verifyEvent(REMOVE, 8, null);

    this.event = null;
    this.eventType = null;
    this.listHolder.removeItem(4);
    this.verifyEvent(REMOVE, 7, "E");

    this.event = null;
    this.eventType = null;
    this.listHolder.addItems(0, this.buildList());
    this.verifyEvent(ADD);
    assertEquals(this.buildList(), CollectionTools.list(this.event.items()));

    this.event = null;
    this.eventType = null;
    this.listHolder.replaceItem(0, "AA");
    this.verifyEvent(REPLACE);
    assertFalse(CollectionTools.contains(this.event.items(), "A"));
    assertTrue(CollectionTools.contains(this.event.items(), "AA"));
  }
コード例 #2
0
 public void testToArray() {
   Object[] a = this.bag.toArray();
   assertEquals(11, a.length);
   assertTrue(CollectionTools.contains(a, null));
   assertTrue(CollectionTools.contains(a, this.one));
   assertTrue(CollectionTools.contains(a, this.two));
   assertTrue(CollectionTools.contains(a, this.three));
   assertTrue(CollectionTools.contains(a, this.four));
 }
コード例 #3
0
 public void testToArrayObjectArray() {
   String[] a = new String[12];
   a[11] = "not null";
   String[] b = (String[]) this.bag.toArray(a);
   assertEquals(a, b);
   assertEquals(12, a.length);
   assertTrue(CollectionTools.contains(a, null));
   assertTrue(CollectionTools.contains(a, this.one));
   assertTrue(CollectionTools.contains(a, this.two));
   assertTrue(CollectionTools.contains(a, this.three));
   assertTrue(CollectionTools.contains(a, this.four));
   assertTrue(a[11] == null);
 }
 private void removeSelectedFieldPairs() {
   for (Iterator stream =
           CollectionTools.iterator(this.fieldPairsSelectionModel.getSelectedValues());
       stream.hasNext(); ) {
     ((MWXmlReferenceMapping) this.subject()).removeXmlFieldPair((MWXmlFieldPair) stream.next());
   }
 }
コード例 #5
0
 private Collection buildServerPlatformNames() {
   Collection servers =
       CollectionTools.sortedSet(ServerPlatformManager.instance().platformShortNames());
   String serverClassName = NullServerPlatformAdapter.instance().getServerClassName();
   servers.remove(ClassTools.shortNameForClassNamed(serverClassName));
   return servers;
 }
コード例 #6
0
 public void referenceDescriptorChanged(MWDescriptor newReferenceDescriptor) {
   if (newReferenceDescriptor == null
       || (getKeyMethod() != null
           && !CollectionTools.contains(candidateKeyMethods(), getKeyMethod()))) {
     setKeyMethod(null);
   }
 }
 public void testSize() {
   this.extendedListHolder.addListChangeListener(ValueModel.VALUE, this.buildListener());
   assertEquals(
       this.buildExtendedList().size(),
       CollectionTools.size((Iterator) this.extendedListHolder.getValue()));
   assertEquals(this.buildExtendedList().size(), this.extendedListHolder.size());
 }
コード例 #8
0
  void renameSelectedPreference() {
    PreferencePropertyValueModel preference = this.selectedPreference();
    if (preference == null) {
      return;
    }

    String name = this.promptForPreferenceName();
    if (name == null) {
      return;
    }

    Preferences preferences = this.selectedPreferences();
    try {
      if (CollectionTools.contains(preferences.keys(), name)) {
        return;
      }
    } catch (BackingStoreException ex) {
      this.handleException(ex);
      return;
    }

    String value = (String) preference.getValue();
    preferences.put(name, value);
    preferences.remove(preference.getKey());
    try {
      // flush the changes, so events are fired and the table is updated
      preferences.flush();
    } catch (BackingStoreException ex) {
      this.handleException(ex);
      return; // skip the selection of a node that might not be there...
    }
    this.tableSelectionModel.setSelectedValue(this.preference(name));
  }
コード例 #9
0
  void addPreferenceToSelectedNode() {
    Preferences preferences = this.selectedPreferences();
    if (preferences == null) {
      return;
    }
    String name = this.promptForPreferenceName();
    if (name == null) {
      return;
    }

    try {
      if (CollectionTools.contains(preferences.keys(), name)) {
        return;
      }
    } catch (BackingStoreException ex) {
      this.handleException(ex);
      return; // skip the selection of a row that might not be there...
    }
    preferences.put(name, "");
    try {
      // flush the change, so an event is fired and the preference is
      // created and added to the table before we try to select it
      preferences.flush();
    } catch (BackingStoreException ex) {
      this.handleException(ex);
      return; // skip the selection of a row that might not be there...
    }
    this.tableSelectionModel.setSelectedValue(this.preference(name));
  }
コード例 #10
0
  private ComboBoxModel buildEisPlatformCollectionHolder() {
    Collection platforms =
        CollectionTools.sortedSet(EisPlatformManager.instance().platformShortNames());

    return new ComboBoxModelAdapter(
        new SimpleCollectionValueModel(platforms), buildEisPlatformHolder());
  }
コード例 #11
0
  public void testSerialization() throws Exception {
    IdentityHashBag bag2 = (IdentityHashBag) TestTools.serialize(this.bag);

    assertTrue("same object?", this.bag != bag2);
    assertEquals(11, bag2.size());
    assertEquals(CollectionTools.bag(this.bag.iterator()), CollectionTools.bag(bag2.iterator()));
    // look for similar elements
    assertTrue(CollectionTools.bag(bag2.iterator()).contains(null));
    assertTrue(CollectionTools.bag(bag2.iterator()).contains("one"));
    assertTrue(CollectionTools.bag(bag2.iterator()).contains("two"));
    assertTrue(CollectionTools.bag(bag2.iterator()).contains("three"));
    assertTrue(CollectionTools.bag(bag2.iterator()).contains("four"));

    int nullCount = 0, oneCount = 0, twoCount = 0, threeCount = 0, fourCount = 0;
    for (Iterator stream = bag2.iterator(); stream.hasNext(); ) {
      String next = (String) stream.next();
      if (next == null) nullCount++;
      else if (next.equals("one")) oneCount++;
      else if (next.equals("two")) twoCount++;
      else if (next.equals("three")) threeCount++;
      else if (next.equals("four")) fourCount++;
    }
    assertEquals(1, nullCount);
    assertEquals(1, oneCount);
    assertEquals(2, twoCount);
    assertEquals(3, threeCount);
    assertEquals(4, fourCount);
  }
コード例 #12
0
 /** sort and return only the names of the "user" types (non-core and non-stub types) */
 private Collection getUserTypeNamesForTopLink() {
   List names = new ArrayList(this.userTypes.size());
   synchronized (this.userTypes) {
     for (Iterator stream = this.userTypes.iterator(); stream.hasNext(); ) {
       names.add(((MWClass) stream.next()).getName());
     }
   }
   return CollectionTools.sort(names, Collator.getInstance());
 }
コード例 #13
0
 /** Add nodes for the preferences's "children" (which are other preferenceses). */
 private void initializeChildNodes() throws BackingStoreException {
   Preferences preferences = this.preferences();
   String[] childrenNames =
       (String[]) CollectionTools.sort(preferences.childrenNames(), this.collator());
   int len = childrenNames.length;
   for (int i = 0; i < len; i++) {
     this.add(this.buildNode(preferences.node(childrenNames[i])));
   }
 }
コード例 #14
0
  /** Returns a collection of session names. */
  Collection<String> getPoolNames() {

    return CollectionTools.collection(
        new TransformationIterator(pools()) {
          protected Object transform(Object next) {
            return ((ConnectionPoolAdapter) next).getName();
          }
        });
  }
 private boolean listContainsAny(Collection items) {
   List extendedList = CollectionTools.list((ListIterator) this.listHolder.getValue());
   for (Iterator stream = items.iterator(); stream.hasNext(); ) {
     if (extendedList.contains(stream.next())) {
       return true;
     }
   }
   return false;
 }
コード例 #16
0
 private Object[] path(String node) {
   Object temp = node;
   List reversePath = new ArrayList();
   do {
     reversePath.add(temp);
     temp = this.parents.get(temp);
   } while (temp != null);
   return CollectionTools.reverse(reversePath).toArray();
 }
コード例 #17
0
 protected void execute() {
   Iterator nodesIterator = CollectionTools.iterator(this.selectedNodes());
   Iterator schemasIterator =
       new TransformationIterator(nodesIterator) {
         protected Object transform(Object next) {
           return ((XmlSchemaNode) next).getSchema();
         }
       };
   SchemaDialogUtilities.reloadSchemas(getWorkbenchContext(), schemasIterator);
 }
コード例 #18
0
  private ListIterator attributeDetails() {
    SchemaComponentDetail[] details = new SchemaComponentDetail[4];

    details[0] = this.buildTypeDetail();
    details[1] = this.buildDefaultDetail();
    details[2] = this.buildFixedDetail();
    details[3] = this.buildUseDetail();

    return CollectionTools.listIterator(details);
  }
コード例 #19
0
 private void checkKeyMethod(MWMethod keyMethod, List currentProblems) {
   if (keyMethod.isCandidateMapContainerPolicyKeyMethod()) {
     if (!CollectionTools.contains(this.candidateKeyMethods(), keyMethod)) {
       // the method, by itself, is OK but it's not in the right hierarchy
       currentProblems.add(this.buildProblem(ProblemConstants.MAPPING_KEY_METHOD_NOT_VISIBLE));
     }
   } else {
     currentProblems.add(this.buildProblem(ProblemConstants.MAPPING_KEY_METHOD_NOT_VALID));
   }
 }
コード例 #20
0
  /** From a collection of adapters extract the modelObjects. */
  protected Collection modelObjectsFrom(Collection adapters) {

    Iterator iterator =
        new TransformationIterator(adapters.iterator()) {

          protected Object transform(Object next) {
            return ((SCAdapter) next).getModel();
          }
        };
    return CollectionTools.collection(iterator);
  }
コード例 #21
0
  private static Set buildCoreClassNames() {
    Set result = new HashSet(10000);

    // void, boolean, int, float, etc.
    CollectionTools.addAll(result, MWClass.nonReferenceClassNames());

    List locations = buildCoreClassLocations();
    Classpath cp = new Classpath(locations);
    cp.addClassNamesTo(result);

    return result;
  }
コード例 #22
0
 /**
  * return the classpath with the entries converted to fully qualified files (any relative entries
  * will be resolved relative to the project save directory)
  */
 private File[] buildExternalClassRepositoryClasspath() {
   List<String> coreFiles = buildCoreClassLocations();
   List files = new ArrayList(this.classpathEntriesSize() + coreFiles.size());
   CollectionTools.addAll(files, this.fullyQualifiedClasspathFiles());
   ListIterator<String> coreFileIter = coreFiles.listIterator();
   // hard-code the "core" classes at the back of the classpath
   // so they can be overridden by the client
   while (coreFileIter.hasNext()) {
     files.add(new File(coreFileIter.next()));
   }
   return (File[]) files.toArray(new File[files.size()]);
 }
コード例 #23
0
  /**
   * Finds the next available index in the preferences that will be used to save the location and
   * its classpath.
   */
  private int findNextAvailableIndex(Preferences preferences) {
    int index = 0;
    String newLocation = LOCATION_TAG + index;

    try {
      String[] names = preferences.keys();

      while (CollectionTools.contains(names, newLocation)) {
        newLocation = LOCATION_TAG + ++index;
      }
    } catch (Exception e) {
      // TODO: How to handle it
    }

    return index;
  }
  public void testRemoveItem5() {
    this.extendedListHolder.addListChangeListener(ValueModel.VALUE, this.buildListener());

    assertTrue(this.extendedListContains("i"));
    boolean exCaught = false;
    try {
      this.extendedListHolder.removeItem(
          CollectionTools.indexOf((ListIterator) this.extendedListHolder.getValue(), "i"));
    } catch (IllegalArgumentException ex) {
      if (ex.getMessage().indexOf("suffix") != -1) {
        exCaught = true;
      }
    }
    assertTrue(exCaught);
    assertTrue(this.extendedListContains("i"));
  }
  protected void addField() {
    Iterator selectedFields = this.returningPolicy().updateFields();

    DefaultListChooserDialog dialog =
        RelationalDescriptorComponentFactory.buildReturningPolicyFieldDialog(
            (MWRelationalClassDescriptor) returningPolicy().getParent(),
            CollectionTools.collection(selectedFields),
            getWorkbenchContext(),
            "descriptor.relational.returningPolicy");

    dialog.show();

    if (dialog.wasConfirmed()) {
      MWColumn column = (MWColumn) dialog.selection();
      ((MWRelationalReturningPolicy) this.returningPolicy()).addUpdateField(column);
    }
  }
コード例 #26
0
  public void testNappingHasFieldAssociationsProblem() {
    String problem = ProblemConstants.MAPPING_QUERY_KEY_ASSOCIATIONS_NOT_SPECIFIED;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem, !hasProblem(problem, mapping));

    Iterator associations = CollectionTools.collection(mapping.columnQueryKeyPairs()).iterator();
    while (associations.hasNext()) {
      mapping.removeColumnQueryKeyPair((MWColumnQueryKeyPair) associations.next());
    }

    assertTrue("The mapping should have the problem: " + problem, hasProblem(problem, mapping));
  }
コード例 #27
0
  protected void initializeExchangeRateDescriptor() {
    MWClass exchangeRateClass =
        refreshedTypeNamed(
            "org.eclipse.persistence.tools.workbench.test.models.currency.ExchangeRate");
    MWTable exchangeRateTable = getProject().getDatabase().tableNamed("EXCHANGE_RATE");
    MWTableDescriptor descriptor;
    try {
      descriptor = (MWTableDescriptor) getProject().addDescriptorForType(exchangeRateClass);
    } catch (InterfaceDescriptorCreationException e) {
      throw new RuntimeException(e);
    }

    descriptor.setPrimaryTable(exchangeRateTable);

    // Caching Policy
    descriptor.getCachingPolicy().setCacheSize(405);
    descriptor.getCachingPolicy().setCacheType(MWCachingPolicy.CACHE_TYPE_FULL);
    descriptor
        .getCachingPolicy()
        .setExistenceChecking(MWCachingPolicy.EXISTENCE_CHECKING_CHECK_DATABASE);

    // Direct to field mappings

    addDirectMapping(descriptor, "id", exchangeRateTable, "ID");
    addDirectMapping(descriptor, "periodLength", exchangeRateTable, "PERIOD");

    // Aggregate mappings
    MWAggregateMapping currencyRangeMapping =
        descriptor.addAggregateMapping(descriptor.getMWClass().attributeNamed("currencyRange"));
    MWClass currencyRangeClass =
        refreshedTypeNamed(
            "org.eclipse.persistence.tools.workbench.test.models.currency.CurrencyRange");
    MWAggregateDescriptor currencyRangeDescriptor =
        (MWAggregateDescriptor) getProject().descriptorForType(currencyRangeClass);
    currencyRangeMapping.setReferenceDescriptor(currencyRangeDescriptor);

    Iterator fieldAssociations =
        CollectionTools.sort(currencyRangeMapping.pathsToFields()).iterator();
    String[] fieldNames = new String[] {"HI_UNIT", "HI_VALUE", "LO_UNIT", "LO_VALUE", "TREND"};
    for (int i = 0; i < fieldNames.length; i++) {
      MWAggregatePathToColumn association = (MWAggregatePathToColumn) fieldAssociations.next();
      association.setColumn(exchangeRateTable.columnNamed(fieldNames[i]));
    }
  }
コード例 #28
0
  protected void initializeCommodityPriceDescriptor() {
    MWClass commodityPriceClass =
        refreshedTypeNamed(
            "org.eclipse.persistence.tools.workbench.test.models.currency.CommodityPrice");

    MWTableDescriptor descriptor;
    try {
      descriptor = (MWTableDescriptor) getProject().addDescriptorForType(commodityPriceClass);
    } catch (InterfaceDescriptorCreationException e) {
      throw new RuntimeException(e);
    }

    MWTable table = tableNamed("COMMODITY_PRICE");
    descriptor.setPrimaryTable(table);
    descriptor.setActive(true);

    // Direct to field mappings
    addDirectMapping(descriptor, "id", table, "ID");
    addDirectMapping(descriptor, "type", table, "TYPE");
    addDirectMapping(descriptor, "periodLength", table, "PERIOD");

    // Aggregate mappings
    MWAggregateMapping currencyRangeMapping =
        descriptor.addAggregateMapping(descriptor.getMWClass().attributeNamed("currencyRange"));
    MWClass currencyRangeClass =
        refreshedTypeNamed(
            "org.eclipse.persistence.tools.workbench.test.models.currency.CurrencyRange");
    currencyRangeMapping.setReferenceDescriptor(getProject().descriptorForType(currencyRangeClass));

    Iterator fieldAssociations =
        CollectionTools.sort(currencyRangeMapping.pathsToFields()).iterator();
    String[] fieldNames =
        new String[] {"HIGH_UNIT", "HIGH_VALUE", "LOW_UNIT", "LOW_VALUE", "TREND"};
    for (int i = 0; i < fieldNames.length; i++) {
      MWAggregatePathToColumn association = (MWAggregatePathToColumn) fieldAssociations.next();
      association.setColumn(table.columnNamed(fieldNames[i]));
    }
  }
 private boolean listContainsAll(Collection items) {
   return CollectionTools.containsAll((Iterator) this.listHolder.getValue(), items);
 }
 private boolean listContains(Object item) {
   return CollectionTools.contains((Iterator) this.listHolder.getValue(), item);
 }