Exemple #1
0
 /**
  * Test changing element to a format and then restore to preference format, using a view model
  * provider that applies a format to child elements of a certain level of depth.
  */
 public void testChangeElementFormatApplyDepth() {
   recreateViewModel();
   if (fVMProvider instanceof TestElementFormatVMProvider == false) {
     return;
   }
   TestElementFormatVMProvider myVM = (TestElementFormatVMProvider) fVMProvider;
   String preferenceFormat = IFormattedValues.HEX_FORMAT;
   setInput(IFormattedValues.NATURAL_FORMAT);
   setFormatAndValidate(preferenceFormat, false, false, false);
   int[] myDepths = new int[] {-1, 2};
   for (int depth : myDepths) {
     myVM.elementFormatApplyDepth = depth;
     // set top level element to a format, and verify top and child elements
     // at certain levels have the correct format.
     String[] format = {IFormattedValues.DECIMAL_FORMAT};
     HashMap<String, ElementFormatSetting> map = new HashMap<String, ElementFormatSetting>();
     makeElementFormatSetting(fViewer, TreePath.EMPTY, format, 1, 0, map);
     ArrayList<ElementFormatSetting> setElementFormats =
         new ArrayList<ElementFormatSetting>(map.values());
     HashMap<String, ElementFormatSetting> expMap = new HashMap<String, ElementFormatSetting>();
     makeElementFormatSetting(fViewer, TreePath.EMPTY, format, depth, 0, expMap);
     ArrayList<ElementFormatSetting> expectElementFormats =
         new ArrayList<ElementFormatSetting>(expMap.values());
     setFormatAndValidate(
         preferenceFormat, setElementFormats, expectElementFormats, false, false, false);
     // Restore top level element to preference format, and verify.
     for (ElementFormatSetting e : setElementFormats) {
       e.formatId = null;
     }
     for (ElementFormatSetting e : expectElementFormats) {
       e.formatId = null;
     }
     setFormatAndValidate(
         preferenceFormat, setElementFormats, expectElementFormats, false, false, false);
   }
 }
Exemple #2
0
  /**
   * Test changing element format under manual update policy, using a view model provider that
   * applies a format to child elements of a certain level of depth.
   */
  public void testChangeElementFormatApplyDepthManualUpdateMode() {
    int[] myDepths = new int[] {-1, 2};
    for (int depth : myDepths) {
      recreateViewer();
      if (fVMProvider instanceof TestElementFormatVMProvider == false) {
        return;
      }
      TestElementFormatVMProvider myVM = (TestElementFormatVMProvider) fVMProvider;
      String preferenceFormat = IFormattedValues.NATURAL_FORMAT;
      setInput(IFormattedValues.NATURAL_FORMAT);
      setUpdatePolicy(ManualUpdatePolicy.MANUAL_UPDATE_POLICY_ID);
      myVM.elementFormatApplyDepth = depth;
      // Change top level to a new format, this does not cause the cache entries to be
      // set to dirty.  Retrieving new format values should happen from the service.
      String[] format1 = {IFormattedValues.HEX_FORMAT};
      HashMap<String, ElementFormatSetting> map1 = new HashMap<String, ElementFormatSetting>();
      makeElementFormatSetting(fViewer, TreePath.EMPTY, format1, 1, 0, map1);
      ArrayList<ElementFormatSetting> elementFormats1 =
          new ArrayList<ElementFormatSetting>(map1.values());
      HashMap<String, ElementFormatSetting> expMap1 = new HashMap<String, ElementFormatSetting>();
      makeElementFormatSetting(fViewer, TreePath.EMPTY, format1, depth, 0, expMap1);
      ArrayList<ElementFormatSetting> expectElementFormats1 =
          new ArrayList<ElementFormatSetting>(expMap1.values());
      vmListenerLevel = depth;
      setFormatAndValidate(
          preferenceFormat, elementFormats1, expectElementFormats1, true, false, false);

      // Remove element format and so restore back to preference format - natural.  Values should be
      // retrieved from cache.
      String[] format2 = {null};
      HashMap<String, ElementFormatSetting> map2 = new HashMap<String, ElementFormatSetting>();
      makeElementFormatSetting(fViewer, TreePath.EMPTY, format2, 1, 0, map2);
      ArrayList<ElementFormatSetting> elementFormats2 =
          new ArrayList<ElementFormatSetting>(map2.values());
      HashMap<String, ElementFormatSetting> expMap2 = new HashMap<String, ElementFormatSetting>();
      makeElementFormatSetting(fViewer, TreePath.EMPTY, format2, depth, 0, expMap2);
      ArrayList<ElementFormatSetting> expectElementFormats2 =
          new ArrayList<ElementFormatSetting>(expMap2.values());
      setFormatAndValidate(
          preferenceFormat, elementFormats2, expectElementFormats2, true, true, false);

      // Generate an event which will cause all cache entries to be marked dirty.
      postEventInManualUpdateMode();

      // Change back again to hex format.  Values should be retrieved from cache.
      setFormatAndValidate(
          preferenceFormat, elementFormats1, expectElementFormats1, true, true, false);

      // Change to a decimal, which is not cached, values should come with an error.
      String[] format3 = {IFormattedValues.DECIMAL_FORMAT};
      HashMap<String, ElementFormatSetting> map3 = new HashMap<String, ElementFormatSetting>();
      makeElementFormatSetting(fViewer, TreePath.EMPTY, format3, 1, 0, map3);
      ArrayList<ElementFormatSetting> elementFormats3 =
          new ArrayList<ElementFormatSetting>(map3.values());
      HashMap<String, ElementFormatSetting> expMap3 = new HashMap<String, ElementFormatSetting>();
      makeElementFormatSetting(fViewer, TreePath.EMPTY, format3, depth, 0, expMap3);
      ArrayList<ElementFormatSetting> expectElementFormats3 =
          new ArrayList<ElementFormatSetting>(expMap3.values());
      setFormatAndValidate(
          preferenceFormat, elementFormats3, expectElementFormats3, true, true, true);
    }
  }