private List<EActivity> getActivities(ISelection selection) {
   final Set<EActivity> activitySet = new LinkedHashSet<EActivity>();
   if (selection instanceof IStructuredSelection) {
     IStructuredSelection structuredSelection = (IStructuredSelection) selection;
     Set<EPlanElement> selectedElements = PlanEditorUtil.emfFromSelection(structuredSelection);
     class PlanFound extends RuntimeException {
       /* */
     }
     try {
       new PlanVisitor() {
         @Override
         protected void visit(EPlanElement element) {
           if (element instanceof EActivity) {
             EActivity activity = (EActivity) element;
             activitySet.add(activity);
           } else if (element instanceof EPlan) {
             throw new PlanFound();
           }
         }
       }.visitAll(selectedElements);
     } catch (PlanFound found) {
       activitySet.clear();
     }
   }
   if (activitySet.isEmpty()) {
     List<EActivity> activities = EPlanUtils.getActivities(plan);
     Collections.reverse(activities); // heuristic to prefer to keep the plan earlier
     return activities;
   }
   return new ArrayList<EActivity>(activitySet);
 }
 @Override
 public boolean canSetProperty(Object object) {
   if (object == null) {
     return false;
   } else if (object instanceof EMember) {
     return EPlanUtils.canEdit((EMember) object) && super.canSetProperty(object);
   }
   return super.canSetProperty(object);
 }
 @Override
 public boolean isImportant(TemporalEdgeManager manager, Notification notification) {
   Object feature = notification.getFeature();
   if (TemporalPackage.Literals.TEMPORAL_MEMBER__START_TIME == feature
       || TemporalPackage.Literals.TEMPORAL_MEMBER__DURATION == feature
       || TemporalPackage.Literals.TEMPORAL_MEMBER__END_TIME == feature) {
     return ((TemporalMember) notification.getNotifier()).getPlanElement() instanceof EActivity;
   } else if (PlanPackage.Literals.EPLAN_PARENT__CHILDREN == feature
       || PlanPackage.Literals.EACTIVITY__CHILDREN == feature) {
     return !EPlanUtils.isTemplatePlanHierarchyElement(notification.getNotifier());
   }
   return false;
 }
示例#4
0
 public void execute(File file, String planName, Date startDate, Date stopDate)
     throws IOException {
   if (startDate == null || stopDate == null) {
     return;
   }
   EPlan plan = PlanFactory.eINSTANCE.createEPlan();
   plan.setName(planName);
   URI planURI = URI.createPlatformResourceURI(file.getAbsolutePath(), true);
   Resource resource = EMFUtils.createResourceSet().createResource(planURI);
   resource.getContents().clear();
   resource.getContents().add(plan);
   EPlanUtils.setENamespaceURI(plan, PlanPackage.eNS_URI);
   resource.save(null);
 }
示例#5
0
 public static Collection<ConstraintsMember> getConstraintMembersRecursively(EPlan plan) {
   return EPlanUtils.getMembers(plan, ConstraintsMember.class);
 }
 private Set<EPlanElement> getAffectedElements(List<Notification> notifications) {
   final Set<EPlanElement> affectedElements = new LinkedHashSet<EPlanElement>();
   class RemovalVisitor extends PlanVisitor {
     @Override
     protected void visit(EPlanElement element) {
       affectedElements.remove(element);
     }
   }
   class AdditionVisitor extends PlanVisitor {
     @Override
     protected void visit(EPlanElement element) {
       affectedElements.add(element);
     }
   }
   PlanVisitor removalVisitor = new RemovalVisitor();
   PlanVisitor additionVisitor = new AdditionVisitor();
   for (Notification notification : notifications) {
     Object feature = notification.getFeature();
     Object notifier = notification.getNotifier();
     if ((feature == PlanPackage.Literals.EPLAN_PARENT__CHILDREN)
         || (feature == PlanPackage.Literals.EACTIVITY__CHILDREN)) {
       removalVisitor.visitAll(EPlanUtils.getElementsRemoved(notification));
       additionVisitor.visitAll(EPlanUtils.getElementsAdded(notification));
     } else if ((feature == TemporalPackage.Literals.TEMPORAL_MEMBER__START_TIME)
         || (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__DURATION)
         || (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__END_TIME)
         || (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__SCHEDULED)) {
       EMember member = (EMember) notifier;
       affectedElements.add(member.getPlanElement());
     } else if ((feature == ConstraintsPackage.Literals.CONSTRAINTS_MEMBER__CHAIN)
         || (feature
             == ConstraintsPackage.Literals.CONSTRAINTS_MEMBER__PERIODIC_TEMPORAL_CONSTRAINTS)
         || (feature
             == ConstraintsPackage.Literals.CONSTRAINTS_MEMBER__BINARY_TEMPORAL_CONSTRAINTS)) {
       EMember member = (EMember) notifier;
       affectedElements.add(member.getPlanElement());
     } else if (feature == AdvisorPackage.Literals.IWAIVABLE__WAIVER_RATIONALE) {
       if (notifier instanceof BinaryTemporalConstraint) {
         BinaryTemporalConstraint binary = (BinaryTemporalConstraint) notifier;
         affectedElements.add(binary.getPointA().getElement());
         affectedElements.add(binary.getPointB().getElement());
       } else if (notifier instanceof PeriodicTemporalConstraint) {
         PeriodicTemporalConstraint periodic = (PeriodicTemporalConstraint) notifier;
         affectedElements.add(periodic.getPoint().getElement());
       }
     } else if (ConstraintUtils.areAnchorsAllowed()
         && ADParameterUtils.isActivityAttributeOrParameter(notifier)) {
       EPlanElement planElement = ADParameterUtils.getActivityAttributeOrParameter(notifier);
       List<TemporalConstraint> constraints = new ArrayList<TemporalConstraint>();
       constraints.addAll(ConstraintUtils.getBinaryConstraints(planElement, false));
       constraints.addAll(ConstraintUtils.getPeriodicConstraints(planElement, false));
       for (TemporalConstraint constraint : constraints) {
         if (constraint instanceof BinaryTemporalConstraint) {
           BinaryTemporalConstraint btc = (BinaryTemporalConstraint) constraint;
           if (ConstraintUtils.isAnchorPointForElement(
                   btc.getPointA(), planElement, (EStructuralFeature) feature)
               || ConstraintUtils.isAnchorPointForElement(
                   btc.getPointB(), planElement, (EStructuralFeature) feature)) {
             affectedElements.add(planElement);
             break;
           }
         } else if (constraint instanceof PeriodicTemporalConstraint) {
           PeriodicTemporalConstraint ptc = (PeriodicTemporalConstraint) constraint;
           if (ConstraintUtils.isAnchorPointForElement(
               ptc.getPoint(), planElement, (EStructuralFeature) feature)) {
             affectedElements.add(planElement);
             break;
           }
         }
       }
     }
   }
   return affectedElements;
 }