@Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   Command command = event.getCommand();
   ISelection selection = HandlerUtil.getCurrentSelection(event);
   EList<EPlanElement> elements = getSelectedTemporalElements(selection);
   boolean isChecked = getCommandState(command);
   IUndoContext undoContext = getUndoContext();
   CompositeOperation op = new CompositeOperation(getEarliestOrLatestName());
   if (isChecked) {
     for (EPlanElement element : elements) {
       ConstraintsMember member = element.getMember(ConstraintsMember.class, true);
       Set<PeriodicTemporalConstraint> constraints = getRelevantConstraints(member);
       for (PeriodicTemporalConstraint constraint : constraints) {
         op.add(new DeleteTemporalBoundOperation(constraint));
       }
     }
   } else {
     Object data = showDialog();
     if (data instanceof Amount) {
       Amount<Duration> offset = (Amount<Duration>) data;
       if (!elements.isEmpty()) {
         ECollections.sort(elements, TemporalChainUtils.CHAIN_ORDER);
         for (EPlanElement planElement : elements) {
           op.add(createPeriodicTemporalConstraintOperation(planElement, offset, undoContext));
         }
       }
     }
   }
   CommonUtils.execute(op, undoContext);
   setCommandState(command, !isChecked);
   return null;
 }
Esempio n. 2
0
 /**
  * Returns true if all elements have the same parent
  *
  * @param elements
  * @return
  */
 public static boolean sameParent(List<? extends EPlanElement> elements) {
   EObject firstParent = elements.get(0).eContainer();
   for (EPlanElement element : elements) {
     EObject parent = element.eContainer();
     if (firstParent != parent) {
       return false;
     }
   }
   return true;
 }
Esempio n. 3
0
 public static boolean sameType(List<EPlanElement> elements) {
   Class clazz = null;
   for (EPlanElement element : elements) {
     if (clazz == null) {
       clazz = element.getClass();
     } else if (element.getClass() != clazz) {
       return false;
     }
   }
   return true;
 }
Esempio n. 4
0
 public static void detachConstraint(final BinaryTemporalConstraint constraint) {
   EPlanElement elementA = constraint.getPointA().getElement();
   if (elementA != null) {
     ConstraintsMember memberA = elementA.getMember(ConstraintsMember.class, true);
     memberA.getBinaryTemporalConstraints().remove(constraint);
   }
   EPlanElement elementB = constraint.getPointB().getElement();
   if (elementB != null) {
     ConstraintsMember memberB = elementB.getMember(ConstraintsMember.class, true);
     memberB.getBinaryTemporalConstraints().remove(constraint);
   }
 }
 @Override
 public boolean isCheckedForSelection(ISelection selection) {
   EList<EPlanElement> elements = getSelectedTemporalElements(selection);
   boolean isChecked = !elements.isEmpty();
   for (EPlanElement element : elements) {
     ConstraintsMember member = element.getMember(ConstraintsMember.class, false);
     if (member == null || getRelevantConstraints(member).isEmpty()) {
       isChecked = false;
       break;
     }
   }
   return isChecked;
 }
Esempio n. 6
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);
 }
Esempio n. 7
0
 public static List<BinaryTemporalConstraint> getBinaryConstraints(
     EPlanElement element, boolean mustExist) {
   ConstraintsMember constraintsMember = element.getMember(ConstraintsMember.class, mustExist);
   if (constraintsMember == null) {
     return Collections.emptyList();
   }
   return constraintsMember.getBinaryTemporalConstraints();
 }
Esempio n. 8
0
 public static boolean isNested(List<EPlanElement> elements) {
   Set<String> hierarchy = new HashSet();
   for (EPlanElement element : elements) {
     while (element instanceof EPlanChild
         && (((EPlanChild) element).getParent() instanceof EPlanChild)) {
       EPlanElement parent = ((EPlanChild) element).getParent();
       hierarchy.add(parent.getPersistentID());
       element = parent;
     }
   }
   for (EPlanElement element : elements) {
     if (hierarchy.contains(element.getPersistentID())) {
       return true;
     }
   }
   return false;
 }
Esempio n. 9
0
 /**
  * Get the value of the named AD parameter for the activity
  *
  * @param element
  * @param parameterName
  * @return
  * @throws UndefinedParameterException
  */
 @SuppressWarnings("unchecked")
 public static <T> T getParameterObject(EPlanElement element, String parameterName)
     throws UndefinedParameterException {
   EObject data = element.getData();
   if (data == null)
     throw new UndefinedParameterException("Null data for plan element " + element);
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   return (T) data.eGet(feature);
 }
Esempio n. 10
0
 /**
  * Returns whether or not the rule is waived for this plan
  *
  * @see isEnabled
  * @param rule
  * @return
  */
 public static boolean isWaived(EPlanElement element, ERule rule) {
   RuleAdvisorMember ruleMember = element.getMember(RuleAdvisorMember.class, true);
   List<String> ruleNames =
       WaiverUtils.getExistingWaivedViolations(ruleMember, RuleAdvisorMember.RULE_WAIVERS_KEY);
   if (ruleNames != null) {
     return ruleNames.contains(rule.getName());
   }
   return false;
 }
Esempio n. 11
0
 /**
  * Returns whether activity contains AD parameter of given type
  *
  * @param element
  * @param parameterType
  * @return
  */
 @SuppressWarnings("unchecked")
 public static boolean isParameterForType(EPlanElement element, EClass parameterType) {
   EObject data = element.getData();
   EList<EStructuralFeature> structuralFeatures = data.eClass().getEStructuralFeatures();
   for (int i = 0; i < structuralFeatures.size(); i++) {
     final EStructuralFeature feature = structuralFeatures.get(i);
     if (parameterType == feature.getEType()) return true;
   }
   return false;
 }
Esempio n. 12
0
 /**
  * Get the value of the AD parameter by type for the activity
  *
  * @param element
  * @param parameterType
  * @return
  */
 @SuppressWarnings("unchecked")
 public static <T> Option<T> getParameterObjectByType(EPlanElement element, EClass parameterType) {
   EObject data = element.getData();
   EList<EStructuralFeature> structuralFeatures = data.eClass().getEStructuralFeatures();
   for (int i = 0; i < structuralFeatures.size(); i++) {
     final EStructuralFeature feature = structuralFeatures.get(i);
     if (parameterType == feature.getEType()) return Option.fromNull((T) data.eGet(feature));
   }
   return Option.none();
 }
Esempio n. 13
0
  public static List getReferences(EPlanElement element, String attribute)
      throws UndefinedParameterException {
    EObject data = element.getData();
    if (data == null) {
      return null;
    }

    EStructuralFeature feature = getParameterFeature(data, attribute);
    List groupReferences = (List) data.eGet(feature);
    return groupReferences;
  }
Esempio n. 14
0
 public static String addParameterStringToListCaseInsensitive(
     EPlanElement element, String parameterName, String newValue)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   EClassifier type = feature.getEType();
   if (type instanceof EEnum) {
     EEnum enumType = (EEnum) type;
     EEnumLiteral literal = getCaseInsensitiveValue(enumType, newValue);
     addParameterObjectToList(element, parameterName, literal);
     return literal == null ? null : literal.getLiteral();
   } else {
     addParameterStringToList(element, parameterName, newValue);
     return newValue;
   }
 }
Esempio n. 15
0
 public static List<PeriodicTemporalConstraint> getPeriodicConstraints(
     EPlanElement element, Timepoint timepoint, boolean mustExist) {
   ConstraintsMember constraintsMember = element.getMember(ConstraintsMember.class, mustExist);
   if (constraintsMember == null) {
     return Collections.emptyList();
   }
   List<PeriodicTemporalConstraint> result = new ArrayList<PeriodicTemporalConstraint>();
   for (PeriodicTemporalConstraint constraint :
       constraintsMember.getPeriodicTemporalConstraints()) {
     ConstraintPoint point = constraint.getPoint();
     if ((point.getElement() == element) && (point.getEndpoint() == timepoint)) {
       result.add(constraint);
     }
   }
   return result;
 }
Esempio n. 16
0
 @SuppressWarnings("unchecked")
 public static void addParameterObjectToList(
     EPlanElement element, String parameterName, Object object)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   Object value = data.eGet(feature);
   if (!(value instanceof EList)) {
     Logger logger = Logger.getLogger(ADParameterUtils.class);
     logger.warn("feature value '" + value + "' is not EList: " + parameterName);
     return;
   }
   EList list = (EList) value;
   if (object != null && !list.contains(object)) {
     list.add(object);
   }
 }
Esempio n. 17
0
  /**
   * Add a reference to a named AD
   *
   * @param element
   * @param referenceURI
   * @param referenceID
   * @param attribute
   */
  @SuppressWarnings("unchecked")
  public static void addReference(
      EPlanElement element, URI referenceURI, String referenceID, String attribute) {
    if (referenceURI != null) {
      EObject data = element.getData();
      EStructuralFeature feature = data.eClass().getEStructuralFeature(attribute);
      EClass referenceClass = (EClass) feature.getEType();
      List groupReferences = (List) data.eGet(data.eClass().getEStructuralFeature(attribute));

      URI uri = referenceURI.appendFragment(referenceID);
      EObject groupObject =
          ActivityDictionary.getInstance().getEFactoryInstance().create(referenceClass);
      ((BasicEObjectImpl) groupObject).eSetProxyURI(uri);
      if (!groupReferences.contains(groupObject)) {
        groupReferences.add(groupObject);
      }
    }
  }
 private SuggestedStartTime getSimpleBounds(EPlanElement element) {
   Date latestEarliestStart = null;
   Date earliestLatestStart = null;
   Date latestEarliestEnd = null;
   Date earliestLatestEnd = null;
   for (PeriodicTemporalConstraint timepointConstraint :
       ConstraintUtils.getPeriodicConstraints(element, false)) {
     if (timepointConstraint.getWaiverRationale() != null) {
       continue; // skip this one because it is waived
     }
     Date earliest = ConstraintUtils.getPeriodicConstraintEarliestDate(timepointConstraint);
     Date latest = ConstraintUtils.getPeriodicConstraintLatestDate(timepointConstraint);
     switch (timepointConstraint.getPoint().getEndpoint()) {
       case START:
         latestEarliestStart = pickLater(latestEarliestStart, earliest);
         earliestLatestStart = pickEarlier(earliestLatestStart, latest);
         break;
       case END:
         latestEarliestEnd = pickLater(latestEarliestEnd, earliest);
         earliestLatestEnd = pickEarlier(earliestLatestEnd, latest);
         break;
       default:
         Logger.getLogger(SpifePlanConstraintInfo.class)
             .warn("unexpected timepoint: " + timepointConstraint.getPoint().getEndpoint());
     }
   }
   TemporalExtent extent = element.getMember(TemporalMember.class).getExtent();
   if (extent != null) {
     if (latestEarliestEnd != null) {
       Date earliest = DateUtils.subtract(latestEarliestEnd, extent.getDurationMillis());
       latestEarliestStart = pickLater(latestEarliestStart, earliest);
     }
     if (earliestLatestEnd != null) {
       Date latest = DateUtils.subtract(earliestLatestEnd, extent.getDurationMillis());
       earliestLatestStart = pickEarlier(earliestLatestStart, latest);
     }
   }
   if ((latestEarliestStart == null) || (earliestLatestStart == null)) {
     return null;
   }
   return new SuggestedStartTime(
       element, latestEarliestStart, latestEarliestStart, earliestLatestStart);
 }
 private TemporalBoundEditOperation createPeriodicTemporalConstraintOperation(
     EPlanElement planElement, Amount<Duration> offset, IUndoContext undoContext) {
   ConstraintsMember facet = planElement.getMember(ConstraintsMember.class, true);
   Set<PeriodicTemporalConstraint> oldConstraints = getRelevantConstraints(facet);
   PeriodicTemporalConstraint newConstraint = null;
   for (PeriodicTemporalConstraint oldConstraint : oldConstraints) {
     Amount<Duration> time = getRelevantPartOfConstraint(oldConstraint);
     if (time.compareTo(offset) == 0) {
       return null; // same as an existing pin
     }
   }
   newConstraint = createPeriodicTemporalConstraint(planElement, offset);
   TemporalBoundEditOperation operation =
       new TemporalBoundEditOperation(
           getEarliestOrLatestName(), planElement, oldConstraints, newConstraint);
   if (undoContext != null) {
     operation.addContext(undoContext);
   }
   operation.addContext(undoContext);
   return operation;
 }
Esempio n. 20
0
 /**
  * Add a value to a named AD multi-select EEnum parameter for the activity
  *
  * @param element
  * @param parameterName
  * @param newValue
  * @throws UndefinedParameterException
  */
 @SuppressWarnings("unchecked")
 public static void addParameterStringToList(
     EPlanElement element, String parameterName, String newValue)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   EClassifier type = feature.getEType();
   Object object;
   if (type instanceof EEnum) {
     EEnum enumType = (EEnum) type;
     object = enumType.getEEnumLiteral(newValue);
   } else if (type instanceof EDataType) {
     EDataType dataType = (EDataType) type;
     EPackage typePackage = dataType.getEPackage();
     EFactory factory = typePackage.getEFactoryInstance();
     object = factory.createFromString(dataType, newValue);
   } else {
     Logger logger = Logger.getLogger(ADParameterUtils.class);
     logger.warn("feature type '" + type + "'is not EDataType: " + parameterName);
     object = newValue;
   }
   addParameterObjectToList(element, parameterName, object);
 }
 public FlattenedHierarchyTimelineContentProvider(EPlan ePlan) {
   super(ePlan);
   GROUPING_ACTIVITY_GROUPS.setName(getActivityGroupingName());
   GROUPING_ACTIVITIES.setName(getActivityName());
 }
Esempio n. 22
0
 /**
  * Set the value of the named AD parameter for the activity
  *
  * @param element
  * @param parameterName
  * @param object
  * @throws UndefinedParameterException
  */
 public static void setParameterObject(EPlanElement element, String parameterName, Object newValue)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   data.eSet(feature, newValue);
 }
Esempio n. 23
0
 /**
  * Set the value of the named AD parameter for the activity
  *
  * @param element
  * @param parameterName
  * @param object
  * @throws UndefinedParameterException
  */
 public static void setParameterString(EPlanElement element, String parameterName, String newValue)
     throws UndefinedParameterException {
   setParameterStringInData(element.getData(), parameterName, newValue);
 }
 private List<Violation> findViolations(Collection<EPlanElement> elements) {
   if (!ConstraintsPreferences.isFindTemporalViolations()) {
     return Collections.emptyList();
   }
   // collect things that could be violated
   Set<BinaryTemporalConstraint> relations = new LinkedHashSet<BinaryTemporalConstraint>();
   List<PeriodicTemporalConstraint> bounds = new ArrayList<PeriodicTemporalConstraint>();
   LinkedHashSet<TemporalChain> chains = TemporalChainUtils.getChains(elements, false);
   for (EPlanElement element : elements) {
     relations.addAll(ConstraintUtils.getBinaryConstraints(element, false));
     bounds.addAll(ConstraintUtils.getPeriodicConstraints(element, false));
   }
   // find the violations
   List<Violation> violations = new ArrayList<Violation>();
   for (BinaryTemporalConstraint relation : relations) {
     if (relation.isViolated()) {
       violations.add(new TemporalDistanceViolation(this, this, relation));
     }
   }
   for (PeriodicTemporalConstraint bound : bounds) {
     if (bound.isViolated()) {
       violations.add(new TemporalEndpointViolation(this, this, bound));
     }
   }
   for (TemporalChain chain : chains) {
     EPlanElement lastPlanElement = null;
     TemporalExtent lastExtent = null;
     for (EPlanElement planElement : chain.getElements()) {
       if (planElement == null) {
         continue;
       }
       if (SpifePlanUtils.getScheduled(planElement) == TriState.FALSE) {
         continue;
       }
       TemporalExtent extent = planElement.getMember(TemporalMember.class).getExtent();
       if (extent == null) {
         continue;
       }
       if (lastExtent != null) {
         if (TemporalChainLinkViolation.isViolated(lastExtent.getEnd(), extent.getStart())) {
           violations.add(
               new TemporalChainLinkViolation(
                   this, this, lastPlanElement, lastExtent, planElement, extent));
         }
       }
       lastPlanElement = planElement;
       lastExtent = extent;
     }
   }
   TemporalNetworkMember<?> networkMember = TemporalNetworkMember.get(plan);
   if (networkMember.isConsistent()) {
     this.nogoodParts = Collections.emptySet();
   } else {
     Set<INogoodPart> parts = networkMember.getNogoodParts();
     for (INogoodPart part : parts) {
       violations.add(new NogoodViolation(this, part));
     }
     this.nogoodParts = parts;
   }
   return violations;
 }
Esempio n. 25
0
 /**
  * Get the feature for the named parameter
  *
  * @param element
  * @param name
  * @return
  * @throws UndefinedParameterException
  */
 public static EStructuralFeature getParameterFeature(EPlanElement element, String name)
     throws UndefinedParameterException {
   EObject data = element.getData();
   return getParameterFeature(data, name);
 }
Esempio n. 26
0
 /** Returns a list of the names of all the rules that are currently waived on the element */
 public static EcoreEList<String> getWaivedRuleNames(EPlanElement element) {
   RuleAdvisorMember ruleMember = element.getMember(RuleAdvisorMember.class, true);
   List<String> ruleNames =
       WaiverUtils.getWaivedViolations(ruleMember, RuleAdvisorMember.RULE_WAIVERS_KEY);
   return (EcoreEList<String>) ruleNames;
 }