summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt.toolchain/src/org/rtems/cdt/toolchain/RtemsInstallBspDirectoryValueHandler.java
blob: 9be247e3186cba9a5f31aa65001e7d0604ee3cd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package org.rtems.cdt.toolchain;

import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.core.runtime.IPath;

public class RtemsInstallBspDirectoryValueHandler implements IManagedOptionValueHandler {
  private IPath installedBspLibPath;      // e.g., /opt/rtems_install/i386-rtems4.9/pc686/lib
  
  public RtemsInstallBspDirectoryValueHandler() {
    installedBspLibPath = RtemsEnvironmentVariableSupplier.getRtemsInstallBspLibDirectory();
  }
  
  /**
   * Handles transfer between values between UI element and 
   * back-end in different circumstances.
   * 
   * @param configuration  build configuration of option 
   *                       (may be IConfiguration or IResourceConfiguration)
   * @param holder         contains the holder of the option
   * @param option         the option that is handled
   * @param extraArgument  extra argument for handler
   * @param event          event to be handled, one of the following: 
   *                       (EVENT_OPEN = 1, EVENT_CLOSE = 2, 
   *                        EVENT_SETDEFAULT = 3, 
   *                        EVENT_APPLY = 4, EVENT_LOAD = 5)
   *
   * @return  True when the event was handled, false otherwise.
   * This enables default event handling can take place.
   */
  public boolean handleValue(IBuildObject configuration, IHoldsOptions holder,
      IOption option, String extraArgument, int event) {
    if (event == EVENT_CLOSE) return false;
    
    try {
      String optionValue = (String) option.getValue();
      if (optionValue==null || optionValue.trim().length()<=0) {
        option.setValue(installedBspLibPath.toPortableString());
      }
    } catch (Exception e) {
      return false;
    }
    
    return true;
  }

  /**
   * Checks whether the value of an option is its default value.
   * 
   * @param configuration  build configuration of option 
   *                       (may be IConfiguration or IResourceConfiguration)
   * @param holder         contains the holder of the option
   * @param option         the option that is handled
   * @param extraArgument  extra argument for handler
   *
   * The additional options besides configuration are supplied to  
   * provide enough information for querying the default value from 
   * a potential data storage back-end.
   * 
   * @return  True if the options value is its default value and
   * False otherwise. This enables that default event handling can 
   * take place.
   */
  public boolean isDefaultValue(IBuildObject configuration,
      IHoldsOptions holder, IOption option, String extraArgument) {
    if (installedBspLibPath==null) return false;
        
    return installedBspLibPath.toPortableString().equals(option.getValue());
  }

  /**
   * Checks whether an enumeration value of an option is currently a 
   * valid choice. The use-case for this method is the case, where
   * the set of valid enumerations in the plugin.xml file changes.
   * The UI will remove entries from selection lists if the value 
   * returns false.
   * 
   * @param configuration  build configuration of option 
   *                       (may be IConfiguration or IResourceConfiguration)
   * @param holder         contains the holder of the option
   * @param option         the option that is handled
   * @param extraArgument  extra argument for handler
   * @param enumValue      enumeration value that is to be checked
   *
   * The additional options besides configuration are supplied to  
   * provide enough information for querying information from a 
   * a potential data storage back-end.
   * 
   * @return  True if the enumeration value is valid and False 
   * otherwise.
   */
  public boolean isEnumValueAppropriate(IBuildObject configuration,
      IHoldsOptions holder, IOption option, String extraArgument,
      String enumValue) {
    // By default return true for all the enum values.
    return true;
  }

}