Ejemplo n.º 1
0
 public int getElementCount() {
   if (m_element != null) {
     return m_element.getElementCount();
   } else {
     return m_elementCount;
   }
 }
 public int countPreviousInstances(edu.cmu.cs.stage3.alice.core.Element parent, Object toCheck) {
   if (parent == null) {
     return 0;
   }
   edu.cmu.cs.stage3.alice.core.property.ListProperty list = null;
   if (parent instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.ForEach) {
     list = ((edu.cmu.cs.stage3.alice.core.question.userdefined.ForEach) parent).list;
   }
   if (parent instanceof edu.cmu.cs.stage3.alice.core.response.ForEach) {
     list = ((edu.cmu.cs.stage3.alice.core.response.ForEach) parent).list;
   }
   if (list != null && list.get() == toCheck) {
     if (parent.getParent() != null
         && !(parent.getParent() instanceof edu.cmu.cs.stage3.alice.core.Sandbox)) {
       return countPreviousInstances(parent.getParent(), toCheck) + 1;
     } else {
       return 1;
     }
   }
   if (parent.getParent() != null
       && !(parent.getParent() instanceof edu.cmu.cs.stage3.alice.core.Sandbox)) {
     return countPreviousInstances(parent.getParent(), toCheck);
   } else {
     return 0;
   }
 }
 protected boolean isTopOccurrance(edu.cmu.cs.stage3.alice.core.Element parent, Object toCheck) {
   if (parent == null) {
     return true;
   }
   edu.cmu.cs.stage3.alice.core.property.ListProperty list = null;
   if (parent instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.ForEach) {
     list = ((edu.cmu.cs.stage3.alice.core.question.userdefined.ForEach) parent).list;
   }
   if (parent instanceof edu.cmu.cs.stage3.alice.core.response.ForEach) {
     list = ((edu.cmu.cs.stage3.alice.core.response.ForEach) parent).list;
   }
   if (list != null && list.get() == toCheck) {
     return false;
   }
   return isTopOccurrance(parent.getParent(), toCheck);
 }
Ejemplo n.º 4
0
  public static int getTotalHTMLRows(edu.cmu.cs.stage3.alice.core.Element element) {
    int totalRows = 0;
    if (element instanceof edu.cmu.cs.stage3.alice.core.Response) {
      if (element instanceof edu.cmu.cs.stage3.alice.core.response.IfElseInOrder) {
        totalRows =
            getTotalRowsToRenderForIfElse(
                element,
                ((edu.cmu.cs.stage3.alice.core.response.IfElseInOrder) element).componentResponses);
      } else {
        totalRows = element.getDescendants(edu.cmu.cs.stage3.alice.core.Response.class).length - 1;
        totalRows +=
            element.getDescendants(edu.cmu.cs.stage3.alice.core.response.IfElseInOrder.class)
                .length;
        totalRows +=
            getEmptyRows(
                element.getDescendants(
                    edu.cmu.cs.stage3.alice.core.response.CompositeResponse.class));

        if (edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor
            .IS_JAVA) {
          totalRows +=
              element.getDescendants(edu.cmu.cs.stage3.alice.core.response.CompositeResponse.class)
                      .length
                  - 1; // add
          // on
          // the
          // extra
          // "}"
          // for
          // each
          // composite
        }
      }
    } else if (element instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.Composite
        || element
            instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.UserDefinedQuestion) {
      if (element instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.IfElse) {
        totalRows =
            getTotalRowsToRenderForIfElse(
                element,
                ((edu.cmu.cs.stage3.alice.core.question.userdefined.IfElse) element).components);
      } else {
        totalRows =
            element.getDescendants(
                        edu.cmu.cs.stage3.alice.core.question.userdefined.Component.class)
                    .length
                - 1;
        totalRows +=
            element.getDescendants(edu.cmu.cs.stage3.alice.core.question.userdefined.IfElse.class)
                .length;
        totalRows +=
            getEmptyRows(
                element.getDescendants(
                    edu.cmu.cs.stage3.alice.core.question.userdefined.Composite.class));
        if (edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor
            .IS_JAVA) {
          totalRows +=
              element.getDescendants(
                          edu.cmu.cs.stage3.alice.core.question.userdefined.Composite.class)
                      .length
                  - 1; // add
          // on
          // the
          // extra
          // "}"
          // for
          // each
          // composite
        }
      }
    }
    return totalRows;
  }
Ejemplo n.º 5
0
  public void dissolve() {
    if (m_element.getParent() instanceof edu.cmu.cs.stage3.alice.core.response.CompositeResponse) {
      authoringTool.getUndoRedoStack().startCompound();
      edu.cmu.cs.stage3.alice.core.response.CompositeResponse parent =
          (edu.cmu.cs.stage3.alice.core.response.CompositeResponse) m_element.getParent();
      int index = parent.componentResponses.indexOf(m_element);
      if (parent instanceof edu.cmu.cs.stage3.alice.core.response.IfElseInOrder) {
        if (!parent.componentResponses.contains(m_element)) {
          index =
              ((edu.cmu.cs.stage3.alice.core.response.IfElseInOrder) parent)
                  .elseComponentResponses.indexOf(m_element);
        }
      }
      Object responses[] = m_components.getArrayValue();
      for (int i = 0; i < responses.length; i++) {
        if (responses[i] instanceof edu.cmu.cs.stage3.alice.core.Response) {
          edu.cmu.cs.stage3.alice.core.Response currentResponse =
              (edu.cmu.cs.stage3.alice.core.Response) responses[i];
          currentResponse.removeFromParent();
          currentResponse.setParent(parent);
          parent.componentResponses.add(index + i, currentResponse);
        }
      }
      m_element.removeFromParent();
      authoringTool.getUndoRedoStack().stopCompound();
    } else if (m_element.getParent()
        instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.Composite) {

      authoringTool.getUndoRedoStack().startCompound();
      edu.cmu.cs.stage3.alice.core.question.userdefined.Composite parent =
          (edu.cmu.cs.stage3.alice.core.question.userdefined.Composite) m_element.getParent();
      int index = parent.getIndexOfChild(m_element);
      if (parent instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.IfElse) {
        if (!parent.components.contains(m_element)) {
          index =
              ((edu.cmu.cs.stage3.alice.core.question.userdefined.IfElse) parent)
                  .elseComponents.indexOf(m_element);
        }
      }

      Object questions[] = m_components.getArrayValue();
      for (int i = 0; i < questions.length; i++) {
        if (questions[i] instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.Component) {
          edu.cmu.cs.stage3.alice.core.question.userdefined.Component currentQuestion =
              (edu.cmu.cs.stage3.alice.core.question.userdefined.Component) questions[i];
          currentQuestion.removeFromParent();
          currentQuestion.setParent(parent);
          parent.components.add(index + i, currentQuestion);
        }
      }
      m_element.removeFromParent();
      authoringTool.getUndoRedoStack().stopCompound();
    } else if (m_element.getParent()
        instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.UserDefinedQuestion) {
      authoringTool.getUndoRedoStack().startCompound();
      edu.cmu.cs.stage3.alice.core.question.userdefined.UserDefinedQuestion parent =
          (edu.cmu.cs.stage3.alice.core.question.userdefined.UserDefinedQuestion)
              m_element.getParent();
      int index = parent.getIndexOfChild(m_element);

      Object questions[] = m_components.getArrayValue();
      for (int i = 0; i < questions.length; i++) {
        if (questions[i] instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.Component) {
          edu.cmu.cs.stage3.alice.core.question.userdefined.Component currentQuestion =
              (edu.cmu.cs.stage3.alice.core.question.userdefined.Component) questions[i];
          currentQuestion.removeFromParent();
          currentQuestion.setParent(parent);
          parent.components.add(index + i, currentQuestion);
        }
      }
      m_element.removeFromParent();
      authoringTool.getUndoRedoStack().stopCompound();
    }
  }