/**
  * <code>getPartialPlan</code>
  *
  * @param ppId - <code>Long</code> -
  * @return - <code>PwPartialPlan</code> -
  * @exception ResourceNotFoundException if an error occurs
  * @exception CreatePartialPlanException if the user interrupts the plan creation
  */
 public synchronized PwPartialPlan getPartialPlan(final Long ppId)
     throws ResourceNotFoundException, CreatePartialPlanException {
   for (Iterator it = partialPlans.values().iterator(); it.hasNext(); ) {
     PwPartialPlan pp = (PwPartialPlan) it.next();
     if (pp != null && pp.getId().equals(ppId)) return pp;
   }
   return addPartialPlan(ppId);
 }
Esempio n. 2
0
  /**
   * <code>addSlotNavNode</code>
   *
   * @param slot - <code>PwSlot</code> -
   * @return - <code>SlotNavNode</code> -
   */
  protected final SlotNavNode addSlotNavNode(final PwSlot slot) {
    boolean isDraggable = true;
    PwTimeline timeline = partialPlan.getTimeline(slot.getTimelineId());

    //     System.err.println( "addSlotNavNode id = " + slot.getId());
    //     System.err.println( "entityNavNodeMap ");
    //     List keyList = new ArrayList( entityNavNodeMap.keySet());
    //     Iterator keyItr = keyList.iterator();
    //     while (keyItr.hasNext()) {
    //       Integer key = (Integer) keyItr.next();
    //       System.err.println( "  key " + key + " " + entityNavNodeMap.get( key).getClass());
    //     }

    SlotNavNode slotNavNode = (SlotNavNode) entityNavNodeMap.get(slot.getId());
    if (slotNavNode == null) {
      slotNavNode =
          new SlotNavNode(
              slot,
              new Point(
                  ViewConstants.TIMELINE_VIEW_X_INIT * 2, ViewConstants.TIMELINE_VIEW_Y_INIT * 2),
              getTimelineColor(timeline.getId()),
              isDraggable,
              this);
      entityNavNodeMap.put(slot.getId(), slotNavNode);
      jGoDocument.addObjectAtTail(slotNavNode);
    }
    return slotNavNode;
  } // end addSlotNavNode
Esempio n. 3
0
 public final String toString() {
   StringBuffer buf = new StringBuffer("key=");
   buf.append(id.toString()).append("; ");
   if (type == DbConstants.D_OBJECT) {
     if (partialPlan.getResource(entityId) != null) {
       buf.append("Resource ");
     } else if (partialPlan.getTimeline(entityId) != null) {
       buf.append("Timeline ");
     } else if (partialPlan.getObject(entityId) != null) {
       buf.append("Object ");
     }
   } else if (type == DbConstants.D_TOKEN) {
     buf.append("Token ");
   } else if (type == DbConstants.D_VARIABLE) {
     buf.append("Variable ");
   }
   buf.append("key=").append(entityId.toString());
   return buf.toString();
 }
Esempio n. 4
0
 public final String toOutputString() {
   StringBuffer retval =
       new StringBuffer(partialPlan.getId().toString())
           .append("\t")
           .append(id.toString())
           .append("\t")
           .append(type);
   retval.append("\t").append(entityId.toString()).append("\t");
   if (unit) {
     retval.append(1);
   } else {
     retval.append(0);
   }
   retval.append("\t");
   for (Iterator i = choiceList.iterator(); i.hasNext(); ) {
     retval.append(((PwChoice) i.next()).toOutputString());
   }
   retval.append("\n");
   return retval.toString();
 }
Esempio n. 5
0
  private void mouseRightPopupMenu(final Point viewCoords) {
    String partialPlanName = partialPlan.getPartialPlanName();
    PwPlanningSequence planSequence = PlanWorks.getPlanWorks().getPlanSequence(partialPlan);
    JPopupMenu mouseRightPopup = new JPopupMenu();

    JMenuItem nodeByKeyItem = new JMenuItem("Find by Key");
    createNodeByKeyItem(nodeByKeyItem);
    mouseRightPopup.add(nodeByKeyItem);

    JMenuItem findEntityPathItem = new JMenuItem("Find Entity Path");
    createFindEntityPathItem(findEntityPathItem);
    mouseRightPopup.add(findEntityPathItem);

    if (highlightPathNodesList != null) {
      JMenuItem highlightPathItem = new JMenuItem("Highlight Current Path");
      createHighlightPathItem(highlightPathItem, highlightPathNodesList);
      mouseRightPopup.add(highlightPathItem);
    }

    createOpenViewItems(
        partialPlan,
        partialPlanName,
        planSequence,
        mouseRightPopup,
        viewListenerList,
        ViewConstants.NAVIGATOR_VIEW);

    JMenuItem overviewWindowItem = new JMenuItem("Overview Window");
    createOverviewWindowItem(overviewWindowItem, this, viewCoords);
    mouseRightPopup.add(overviewWindowItem);

    this.createZoomItem(jGoView, zoomFactor, mouseRightPopup, this);

    createAllViewItems(
        partialPlan, partialPlanName, planSequence, viewListenerList, mouseRightPopup);

    ViewGenerics.showPopupMenu(mouseRightPopup, this, viewCoords);
  } // end mouseRightPopupMenu
Esempio n. 6
0
 private boolean isNodeKeyValid(Integer nodeKey) {
   boolean isValid = false;
   PwPartialPlan partialPlan = partialPlanView.getPartialPlan();
   if ((partialPlanView instanceof TemporalExtentView)
       || (partialPlanView instanceof TokenNetworkView)) {
     if (partialPlan.getToken(nodeKey) != null) {
       return true;
     }
   } else if ((partialPlanView instanceof TimelineView)) {
     if ((partialPlan.getToken(nodeKey) != null) || (partialPlan.getSlot(nodeKey) != null)) {
       return true;
     }
   } else if ((partialPlanView instanceof ConstraintNetworkView)) {
     if ((partialPlan.getToken(nodeKey) != null)
         || (partialPlan.getVariable(nodeKey) != null)
         || (partialPlan.getConstraint(nodeKey) != null)) {
       return true;
     }
   } else {
     System.err.println("AskNodeByKey.isNodeKeyValid: " + partialPlanView + " not handled");
     System.exit(-1);
   }
   return isValid;
 } // end isNodeKeyValid
Esempio n. 7
0
 /**
  * <code>renderEntityPathNodes</code>
  *
  * @param findEntityPath - <code>FindEntityPath</code> -
  * @return - <code>List</code> -
  */
 public List renderEntityPathNodes(final FindEntityPath findEntityPath) {
   boolean isLayoutNeeded = false;
   List nodeList = new ArrayList();
   Iterator entityItr = findEntityPath.getEntityKeyList().iterator();
   PwEntity entity = null;
   boolean isFirstNode = true;
   while (entityItr.hasNext()) {
     Integer entityKey = (Integer) entityItr.next();
     // System.err.println( "key " + entityKey);
     if ((entity = partialPlan.getToken(entityKey)) != null) {
       TokenNavNode tokenNode = null;
       if (isFirstNode) {
         isFirstNode = false;
         tokenNode = (TokenNavNode) renderInitialNode(entity);
         if (didRenderInitialNodeChange) {
           isLayoutNeeded = true;
         }
       } else {
         PwToken token = (PwToken) entity;
         tokenNode = addTokenNavNode(token);
         if (!tokenNode.areNeighborsShown()) {
           if (tokenNode.addTokenObjects(tokenNode)) {
             isLayoutNeeded = true;
           }
           tokenNode.setAreNeighborsShown(true);
         }
       }
       nodeList.add(tokenNode);
     } else if ((entity = partialPlan.getVariable(entityKey)) != null) {
       VariableNavNode variableNode = null;
       if (isFirstNode) {
         isFirstNode = false;
         variableNode = (VariableNavNode) renderInitialNode(entity);
         if (didRenderInitialNodeChange) {
           isLayoutNeeded = true;
         }
       } else {
         PwVariable variable = (PwVariable) entity;
         variableNode = addVariableNavNode(variable);
         if (!variableNode.areNeighborsShown()) {
           if (variableNode.addVariableObjects(variableNode)) {
             isLayoutNeeded = true;
           }
           variableNode.setAreNeighborsShown(true);
         }
       }
       nodeList.add(variableNode);
     } else if ((entity = partialPlan.getConstraint(entityKey)) != null) {
       ConstraintNavNode constraintNode = null;
       if (isFirstNode) {
         isFirstNode = false;
         constraintNode = (ConstraintNavNode) renderInitialNode(entity);
         if (didRenderInitialNodeChange) {
           isLayoutNeeded = true;
         }
       } else {
         PwConstraint constraint = (PwConstraint) entity;
         constraintNode = addConstraintNavNode(constraint);
         if (!constraintNode.areNeighborsShown()) {
           if (constraintNode.addConstraintObjects(constraintNode)) {
             isLayoutNeeded = true;
           }
           constraintNode.setAreNeighborsShown(true);
         }
       }
       nodeList.add(constraintNode);
     } else if ((entity = partialPlan.getRuleInstance(entityKey)) != null) {
       RuleInstanceNavNode ruleInstanceNode = null;
       if (isFirstNode) {
         isFirstNode = false;
         ruleInstanceNode = (RuleInstanceNavNode) renderInitialNode(entity);
         if (didRenderInitialNodeChange) {
           isLayoutNeeded = true;
         }
       } else {
         PwRuleInstance ruleInstance = (PwRuleInstance) entity;
         ruleInstanceNode = addRuleInstanceNavNode(ruleInstance);
         if (!ruleInstanceNode.areNeighborsShown()) {
           if (ruleInstanceNode.addRuleInstanceObjects(ruleInstanceNode)) {
             isLayoutNeeded = true;
           }
           ruleInstanceNode.setAreNeighborsShown(true);
         }
       }
       nodeList.add(ruleInstanceNode);
     } else if ((entity = partialPlan.getSlot(entityKey)) != null) {
       SlotNavNode slotNode = null;
       if (isFirstNode) {
         isFirstNode = false;
         slotNode = (SlotNavNode) renderInitialNode(entity);
         if (didRenderInitialNodeChange) {
           isLayoutNeeded = true;
         }
       } else {
         PwSlot slot = (PwSlot) entity;
         slotNode = addSlotNavNode(slot);
         if (!slotNode.areNeighborsShown()) {
           if (slotNode.addSlotObjects(slotNode)) {
             isLayoutNeeded = true;
           }
           slotNode.setAreNeighborsShown(true);
         }
       }
       nodeList.add(slotNode);
     } else if ((entity = partialPlan.getTimeline(entityKey)) != null) {
       TimelineNavNode timelineNode = null;
       if (isFirstNode) {
         isFirstNode = false;
         timelineNode = (TimelineNavNode) renderInitialNode(entity);
         if (didRenderInitialNodeChange) {
           isLayoutNeeded = true;
         }
       } else {
         PwTimeline timeline = (PwTimeline) entity;
         timelineNode = addTimelineNavNode(timeline);
         if (!timelineNode.areNeighborsShown()) {
           if (timelineNode.addTimelineObjects(timelineNode)) {
             isLayoutNeeded = true;
           }
           timelineNode.setAreNeighborsShown(true);
         }
       }
       nodeList.add(timelineNode);
     } else if ((entity = partialPlan.getResource(entityKey)) != null) {
       ResourceNavNode resourceNode = null;
       if (isFirstNode) {
         isFirstNode = false;
         resourceNode = (ResourceNavNode) renderInitialNode(entity);
         if (didRenderInitialNodeChange) {
           isLayoutNeeded = true;
         }
       } else {
         PwResource resource = (PwResource) entity;
         resourceNode = addResourceNavNode(resource);
         if (!resourceNode.areNeighborsShown()) {
           if (resourceNode.addResourceObjects(resourceNode)) {
             isLayoutNeeded = true;
           }
           resourceNode.setAreNeighborsShown(true);
         }
       }
       nodeList.add(resourceNode);
     } else if ((entity = partialPlan.getObject(entityKey)) != null) {
       // PwObject must be last
       ModelClassNavNode objectNode = null;
       if (isFirstNode) {
         isFirstNode = false;
         objectNode = (ModelClassNavNode) renderInitialNode(entity);
         if (didRenderInitialNodeChange) {
           isLayoutNeeded = true;
         }
       } else {
         PwObject object = (PwObject) entity;
         objectNode = addModelClassNavNode(object);
         if (!objectNode.areNeighborsShown()) {
           if (objectNode.addObjects(objectNode)) {
             isLayoutNeeded = true;
           }
           objectNode.setAreNeighborsShown(true);
         }
       }
       nodeList.add(objectNode);
     } else {
       System.err.println(
           "NavigatorView.renderEntityPathNodes: entityKey " + entityKey + " not handled");
     }
   }
   if (isLayoutNeeded) {
     // System.err.println( "NavigatorView.renderEntityPathNodes: setLayoutNeeded");
     setLayoutNeeded();
   }
   setFocusNode(null);
   highlightPathNodesList = nodeList;
   redraw();
   return nodeList;
 } // end renderEntityPathNodes
  /**
   * <code>init</code> - wait for instance to become displayable, determine appropriate font
   * metrics, and render the JGo timeline, and slot widgets
   *
   * <p>These functions are not done in the constructor to avoid: "Cannot measure text until a
   * JGoView exists and is part of a visible window". called by componentShown method on the JFrame
   * JGoView.setVisible( true) must be completed -- use runInit in constructor
   */
  public final void init() {
    handleEvent(ViewListener.EVT_INIT_BEGUN_DRAWING);
    // wait for TimelineView instance to become displayable
    while (!this.isDisplayable()) {
      try {
        Thread.currentThread().sleep(50);
      } catch (InterruptedException excp) {
      }
      // System.err.println( "timelineView displayable " + this.isDisplayable());
    }
    this.computeFontMetrics(this);

    QueryHeaderView headerJGoView = new QueryHeaderView(query);
    headerJGoView.validate();
    headerJGoView.setVisible(true);

    FixedHeightPanel variableHeaderPanel = new FixedHeightPanel(headerJGoView, this);
    variableHeaderPanel.setLayout(new BoxLayout(variableHeaderPanel, BoxLayout.Y_AXIS));
    variableHeaderPanel.add(headerJGoView, BorderLayout.NORTH);
    add(variableHeaderPanel, BorderLayout.NORTH);

    String[] columnNames = {
      ViewConstants.DB_TRANSACTION_STEP_NUM_HEADER,
      ViewConstants.QUERY_VARIABLE_KEY_HEADER,
      ViewConstants.QUERY_VARIABLE_TYPE_HEADER,
      ViewConstants.DB_TRANSACTION_PARENT_HEADER,
      // empty last column to allow user adjusting of column widths
      ""
    };
    PwPartialPlan partialPlan = null;
    try {
      partialPlan = planSequence.getPartialPlan(stepNumber);
    } catch (ResourceNotFoundException rnfExcep) {
      int index = rnfExcep.getMessage().indexOf(":");
      JOptionPane.showMessageDialog(
          PlanWorks.getPlanWorks(),
          rnfExcep.getMessage().substring(index + 1),
          "Resource Not Found Exception",
          JOptionPane.ERROR_MESSAGE);
      System.err.println(rnfExcep);
      rnfExcep.printStackTrace();
    }
    Object[][] data = new Object[variableList.size()][columnNames.length];
    for (int row = 0, nRows = variableList.size(); row < nRows; row++) {
      PwVariableQuery variable = (PwVariableQuery) variableList.get(row);
      data[row][0] = variable.getStepNumber().toString();
      data[row][1] = variable.getId().toString();
      data[row][2] = variable.getType();
      data[row][3] = partialPlan.getVariableParentName(variable.getParentId());
    }
    objectKeyColumnIndx = 1;
    stepNumberColumnIndx = 0;
    TableSorter sorter = new TableSorter(new DBTransactionTableModel(columnNames, data));
    variableTable = new DBTransactionTable(sorter, stepNumberColumnIndx, this);
    sorter.setTableHeader(variableTable.getTableHeader());
    contentScrollPane = new JScrollPane(variableTable);
    add(contentScrollPane, BorderLayout.SOUTH);

    this.setVisible(true);

    int maxViewWidth = (int) headerJGoView.getDocumentSize().getWidth();
    int maxViewHeight =
        (int)
            (headerJGoView.getDocumentSize().getHeight()
                +
                // contentJGoView.getDocumentSize().getHeight());
                // keep contentJGoView small
                (ViewConstants.INTERNAL_FRAME_X_DELTA));
    viewFrame.setSize(
        maxViewWidth + ViewConstants.MDI_FRAME_DECORATION_WIDTH,
        maxViewHeight + ViewConstants.MDI_FRAME_DECORATION_HEIGHT);
    int maxQueryFrameY =
        (int)
            (sequenceQueryWindow.getSequenceQueryFrame().getLocation().getY()
                + sequenceQueryWindow.getSequenceQueryFrame().getSize().getHeight());
    int delta =
        Math.min(
            ViewConstants.INTERNAL_FRAME_X_DELTA_DIV_4
                * sequenceQueryWindow.getQueryResultFrameCnt(),
            (int)
                (PlanWorks.getPlanWorks().getSize().getHeight()
                    - maxQueryFrameY
                    - (ViewConstants.MDI_FRAME_DECORATION_HEIGHT * 2)));
    viewFrame.setLocation(ViewConstants.INTERNAL_FRAME_X_DELTA + delta, maxQueryFrameY + delta);
    // prevent right edge from going outside the MDI frame
    expandViewFrame(
        viewFrame,
        Math.max(
            (int) headerJGoView.getDocumentSize().getWidth(),
            variableTable.getColumnModel().getTotalColumnWidth()),
        (int)
            (headerJGoView.getDocumentSize().getHeight()
                + variableTable.getRowCount() * variableTable.getRowHeight()));

    long stopTimeMSecs = System.currentTimeMillis();
    System.err.println(
        "   ... '"
            + this.getName()
            + "'elapsed time: "
            + (stopTimeMSecs - startTimeMSecs)
            + " msecs.");
    handleEvent(ViewListener.EVT_INIT_ENDED_DRAWING);
  } // end init