示例#1
0
 /**
  * Get the value of the named AD parameter for the activity as a string. Works with several types,
  * not just strings -- enums, for example.
  *
  * @param element
  * @param parameterName
  * @return null if the parameter is not found
  */
 public static String getParameterString(EPlanElement element, String parameterName) {
   EObject data = element.getData();
   if (data == null) return null;
   EStructuralFeature feature;
   try {
     feature = getParameterFeature(data, parameterName);
   } catch (UndefinedParameterException e) {
     return null;
   }
   Object object = data.eGet(feature);
   if (object instanceof EEnumLiteral) {
     EEnumLiteral literal = (EEnumLiteral) object;
     return literal.getName();
   }
   EClassifier type = feature.getEType();
   if (type instanceof EDataType) {
     EDataType dataType = (EDataType) type;
     EPackage typePackage = dataType.getEPackage();
     EFactory factory = typePackage.getEFactoryInstance();
     String string = factory.convertToString(dataType, object);
     return string;
   }
   LogUtil.warnOnce("feature type '" + type + "'is not EDataType: " + parameterName);
   return String.valueOf(object);
 }
示例#2
0
 public static String addParameterStringToListCaseInsensitiveSafely(
     EPlanElement element, String parameterName, String newValue) {
   try {
     return addParameterStringToListCaseInsensitive(element, parameterName, newValue);
   } catch (UndefinedParameterException e) {
     LogUtil.error(e);
     return null;
   }
 }
示例#3
0
 /**
  * Create the new-plan wizard and open the dialog
  *
  * @param action ignored
  */
 @Override
 public void run(IAction action) {
   // switch to the planning perspective
   IWorkbench workbench = PlatformUI.getWorkbench();
   try {
     NewPlanWizard planWizard = MissionExtender.construct(NewPlanWizard.class);
     planWizard.init(workbench, null);
     Shell parent = workbench.getActiveWorkbenchWindow().getShell();
     WizardDialog dialog = new WizardDialog(parent, planWizard);
     dialog.create();
     dialog.open();
   } catch (ConstructionException e) {
     LogUtil.error("Error constructing the NewPlanWizard: " + e, e);
   }
 }
示例#4
0
 private static Set<ERule> convertNamesToRules(List<String> ruleNames) {
   if (ruleNames == null) {
     return Collections.emptySet();
   }
   Set<ERule> waivedRules = new LinkedHashSet<ERule>();
   for (String ruleName : ruleNames) {
     ERule rule = AD.getDefinition(ERule.class, ruleName);
     if (rule != null) {
       waivedRules.add(rule);
     } else {
       LogUtil.warn("unknown rule: " + rule);
     }
   }
   return waivedRules;
 }
 /**
  * If the extension registry for PlanFactory has an element the action of which is the given ID
  * string, return the PlanFactory; otherwise return null string,
  *
  * @param id the required value of the element's "action" attribute
  * @return the PlanFactory instance if found; otherwise null
  */
 public IPlanFactory getAction(String id) {
   IExtensionRegistry registry = Platform.getExtensionRegistry();
   IConfigurationElement[] elements =
       registry.getConfigurationElementsFor("gov.nasa.ensemble.core.model.plan.PlanFactory");
   for (int i = 0; i < elements.length; i++) {
     IConfigurationElement element = elements[i];
     if (id.equals(element.getAttribute("action")))
       try {
         return (IPlanFactory) element.createExecutableExtension("class");
       } catch (CoreException e) {
         LogUtil.error("Unable to instantiate action:", e);
       }
   }
   return null;
 }