public void mouseMoved(MouseEvent e) {
      EditorImpl.MyScrollBar scrollBar = myEditor.getVerticalScrollBar();
      int buttonHeight = scrollBar.getDecScrollButtonHeight();
      int lineCount =
          getDocument().getLineCount() + myEditor.getSettings().getAdditionalLinesCount();
      if (lineCount == 0) {
        return;
      }

      if (e.getY() < buttonHeight && myErrorStripeRenderer != null) {
        showTrafficLightTooltip(e);
        return;
      }

      if (showToolTipByMouseMove(e, getWidth())) {
        scrollbar.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        return;
      }

      cancelMyToolTips(e, false);

      if (scrollbar.getCursor().equals(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR))) {
        scrollbar.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }
    }
  private boolean findEntry() {
    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    boolean matchCase = searchDialog.getMatchCase();
    boolean matchWord = searchDialog.getMatchWord();
    String searchString = searchDialog.getSearchString();
    int column = searchDialog.getSelectedSearchArea();

    searchString = matchCase ? searchString : searchString.toLowerCase();

    boolean found = false;
    if (searchDialog.getSearchDown()) {
      for (int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) {
        if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) {
          table.setSelection(i);
          break;
        }
      }
    } else {
      for (int i = table.getSelectionIndex() - 1; i > -1; i--) {
        if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) {
          table.setSelection(i);
          break;
        }
      }
    }

    shell.setCursor(null);
    if (waitCursor != null) waitCursor.dispose();

    return found;
  }
예제 #3
0
  protected boolean refreshFeatureSelection(String layerName, String id) {

    try {
      if (id == null || geopistaEditor == null) return false;
      this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      geopistaEditor.getSelectionManager().clear();
      GeopistaLayer geopistaLayer =
          (GeopistaLayer) geopistaEditor.getLayerManager().getLayer(layerName);
      Collection collection = searchByAttribute(geopistaLayer, 0, id);
      Iterator it = collection.iterator();
      if (it.hasNext()) {
        Feature feature = (Feature) it.next();
        geopistaEditor.select(geopistaLayer, feature);
      }
      geopistaEditor.zoomToSelected();
      this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      return true;
    } catch (Exception ex) {
      this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      ex.printStackTrace(pw);
      logger.error("Exception: " + sw.toString());
      return false;
    }
  }
예제 #4
0
 /**
  * Long operations need to display an hourglass.
  *
  * @param comp The <code>JComponent</code> on which to apply the hour glass cursor
  * @param on If true, we set the cursor on the hourglass
  */
 public static void setCursorOnWait(Component comp, boolean on) {
   if (on) {
     if (comp instanceof AbstractEditorPanel) ((AbstractEditorPanel) comp).showWaitCursor();
     else comp.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   } else {
     if (comp instanceof AbstractEditorPanel) ((AbstractEditorPanel) comp).hideWaitCursor();
     else comp.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
   }
 }
예제 #5
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String filePickerResult = "";
    if (data != null && resultCode == RESULT_OK) {
      try {
        ContentResolver cr = getContentResolver();
        Uri uri = data.getData();
        Cursor cursor =
            GeckoApp.mAppContext
                .getContentResolver()
                .query(uri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null);
        String name = null;
        if (cursor != null) {
          try {
            if (cursor.moveToNext()) {
              name = cursor.getString(0);
            }
          } finally {
            cursor.close();
          }
        }
        String fileName = "tmp_";
        String fileExt = null;
        int period;
        if (name == null || (period = name.lastIndexOf('.')) == -1) {
          String mimeType = cr.getType(uri);
          fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType);
        } else {
          fileExt = name.substring(period);
          fileName = name.substring(0, period);
        }
        File file = File.createTempFile(fileName, fileExt, sGREDir);

        FileOutputStream fos = new FileOutputStream(file);
        InputStream is = cr.openInputStream(uri);
        byte[] buf = new byte[4096];
        int len = is.read(buf);
        while (len != -1) {
          fos.write(buf, 0, len);
          len = is.read(buf);
        }
        fos.close();
        filePickerResult = file.getAbsolutePath();
      } catch (Exception e) {
        Log.e(LOG_FILE_NAME, "showing file picker", e);
      }
    }
    try {
      mFilePickerResult.put(filePickerResult);
    } catch (InterruptedException e) {
      Log.i(LOG_FILE_NAME, "error returning file picker result", e);
    }
  }
예제 #6
0
 /**
  * Invoked when an action occurs.
  *
  * @param e ActionEvent
  * @todo Implement this java.awt.event.ActionListener method
  */
 public void actionPerformed(ActionEvent e) {
   try {
     setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     if (e.getSource() == addButton) {
       processAddEvent();
     } else if (e.getSource() == editButton) {
       processEditEvent();
     } else if (e.getSource() == delButton) {
       processDeleteEvent();
     }
     processTaskTable();
   } finally {
     setCursor(Cursor.getDefaultCursor());
   }
 }
 protected AvaticaResultSet execute2(Cursor cursor, List<ColumnMetaData> columnMetaDataList) {
   this.cursor = cursor;
   this.accessorList = cursor.createAccessors(columnMetaDataList, localCalendar, this);
   this.row = -1;
   this.afterLast = false;
   return this;
 }
예제 #8
0
 /**
  * Executes this result set. (Not a JDBC method.)
  *
  * <p>Note that execute cannot occur in the constructor, because the constructor occurs while the
  * statement is locked, to make sure that execute/cancel don't happen at the same time.
  *
  * @see net.hydromatic.avatica.AvaticaConnection.Trojan#execute(AvaticaResultSet)
  */
 protected AvaticaResultSet execute() {
   this.cursor = statement.connection.meta.createCursor(this);
   this.accessorList = cursor.createAccessors(columnMetaDataList, localCalendar);
   this.row = -1;
   this.afterLast = false;
   return this;
 }
예제 #9
0
  protected String refreshListSelection(String layerName) {
    try {

      Collection collection = geopistaEditor.getSelection();
      if (collection.iterator().hasNext()) {
        GeopistaFeature feature = (GeopistaFeature) collection.iterator().next();
        if (feature == null) {
          logger.error("feature: " + feature);
          return null;
        }

        if (layerName != null && feature.getLayer() != null) {
          if (!layerName.equals(feature.getLayer().getName())) return null;
        }
        // String id = checkNull(feature.getAttribute(0));
        String id = checkNull(feature.getSystemId());
        logger.info("id: -" + id + "-");
        return id;
      }
    } catch (Exception ex) {

      this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      ex.printStackTrace(pw);
      logger.error("Exception: " + sw.toString());
      return null;
    }
    return null;
  }
예제 #10
0
  /** Initialize the panel containing the node. */
  public PluginListCellRenderer() {
    super(new BorderLayout(8, 8));

    JPanel mainPanel = new JPanel(new BorderLayout());

    this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    this.setBackground(Color.WHITE);

    this.setOpaque(true);

    mainPanel.setOpaque(false);
    this.nameVersionPanel.setOpaque(false);

    this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    this.nameLabel.setIconTextGap(2);

    this.nameLabel.setFont(this.getFont().deriveFont(Font.BOLD));
    this.systemLabel.setFont(this.getFont().deriveFont(Font.BOLD));

    this.nameVersionPanel.add(nameLabel);
    this.nameVersionPanel.add(versionLabel);

    mainPanel.add(nameVersionPanel, BorderLayout.NORTH);
    mainPanel.add(descriptionLabel, BorderLayout.CENTER);

    this.add(iconLabel, BorderLayout.WEST);

    this.add(mainPanel, BorderLayout.CENTER);
    this.add(stateLabel, BorderLayout.WEST);
  }
  @Override
  public void mouseMoved(MouseEvent e) {
    Component source = e.getComponent();
    Point location = e.getPoint();
    direction = 0;

    if (location.x < dragInsets.left) direction += WEST;

    if (location.x > source.getWidth() - dragInsets.right - 1) direction += EAST;

    if (location.y < dragInsets.top) direction += NORTH;

    if (location.y > source.getHeight() - dragInsets.bottom - 1) direction += SOUTH;

    //  Mouse is no longer over a resizable border

    if (direction == 0) {
      source.setCursor(sourceCursor);
    } else // use the appropriate resizable cursor
    {
      int cursorType = cursors.get(direction);
      Cursor cursor = Cursor.getPredefinedCursor(cursorType);
      source.setCursor(cursor);
    }
  }
예제 #12
0
  public InfoAndProgressPanel() {

    setOpaque(false);

    myRefreshIcon = new RefreshFileSystemIcon();
    //  new AsyncProcessIcon("Refreshing filesystem") {
    //  protected Icon getPassiveIcon() {
    //    return myEmptyRefreshIcon;
    //  }
    //
    //  @Override
    //  public Dimension getPreferredSize() {
    //    if (!isRunning()) return new Dimension(0, 0);
    //    return super.getPreferredSize();
    //  }
    //
    //  @Override
    //  public void paint(Graphics g) {
    //    g.translate(0, -1);
    //    super.paint(g);
    //    g.translate(0, 1);
    //  }
    // };

    myRefreshIcon.setPaintPassiveIcon(false);

    myRefreshAndInfoPanel.setLayout(new BorderLayout());
    myRefreshAndInfoPanel.setOpaque(false);
    myRefreshAndInfoPanel.add(myRefreshIcon, BorderLayout.WEST);
    myRefreshAndInfoPanel.add(myInfoPanel, BorderLayout.CENTER);

    myProgressIcon = new AsyncProcessIcon("Background process");
    myProgressIcon.setOpaque(false);

    myProgressIcon.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            handle(e);
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            handle(e);
          }
        });

    myProgressIcon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    myProgressIcon.setBorder(StatusBarWidget.WidgetBorder.INSTANCE);
    myProgressIcon.setToolTipText(ActionsBundle.message("action.ShowProcessWindow.double.click"));

    myUpdateQueue =
        new MergingUpdateQueue("Progress indicator", 50, true, MergingUpdateQueue.ANY_COMPONENT);
    myPopup = new ProcessPopup(this);

    setRefreshVisible(false);

    restoreEmptyStatus();
  }
 @Override
 public void deactivate(DrawingEditor editor) {
   super.deactivate(editor);
   getView().setCursor(Cursor.getDefaultCursor());
   getView().setActiveHandle(null);
   clearHoverHandles();
   dragLocation = null;
 }
  private boolean save() {
    if (file == null) return saveAs();

    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    TableItem[] items = table.getItems();
    String[] lines = new String[items.length];
    for (int i = 0; i < items.length; i++) {
      String[] itemText = new String[table.getColumnCount()];
      for (int j = 0; j < itemText.length; j++) {
        itemText[j] = items[i].getText(j);
      }
      lines[i] = encodeLine(itemText);
    }

    FileWriter fileWriter = null;
    try {
      fileWriter = new FileWriter(file.getAbsolutePath(), false);
      for (int i = 0; i < lines.length; i++) {
        fileWriter.write(lines[i]);
      }
    } catch (FileNotFoundException e) {
      displayError(resMessages.getString("File_not_found") + "\n" + file.getName());
      return false;
    } catch (IOException e) {
      displayError(resMessages.getString("IO_error_write") + "\n" + file.getName());
      return false;
    } finally {
      shell.setCursor(null);
      waitCursor.dispose();

      if (fileWriter != null) {
        try {
          fileWriter.close();
        } catch (IOException e) {
          displayError(resMessages.getString("IO_error_close") + "\n" + file.getName());
          return false;
        }
      }
    }

    shell.setText(resMessages.getString("Title_bar") + file.getName());
    isModified = false;
    return true;
  }
예제 #15
0
 public void close() {
   closed = true;
   final Cursor cursor = this.cursor;
   if (cursor != null) {
     this.cursor = null;
     cursor.close();
   }
   statement.onResultSetClose(this);
   // TODO: for timeout, see IteratorResultSet.close
   /*
           if (timeoutCursor != null) {
               final long noTimeout = 0;
               timeoutCursor.close(noTimeout);
               timeoutCursor = null;
           }
   */
 }
  private static void construyeListaFiltros() {

    int tmpInt;
    String tmpString;

    listaFiltros = new ArrayList<DatosFiltro>();
    DatosFiltro fltAnio = new DatosFiltro("Año", "year");
    Cursor cr = getAniosDiferentes();

    while (cr.moveToNext()) {
      tmpInt = cr.getInt(0);
      tmpString = String.valueOf(tmpInt).trim();
      fltAnio.addValor(tmpInt, tmpString);
    }
    cr.close();

    listaFiltros.add(fltAnio);

    DatosFiltro fltMes = new DatosFiltro("Mes", "month");

    cr = getMesesDiferentes();

    while (cr.moveToNext()) {
      tmpInt = cr.getInt(0);
      tmpString = Utilidades.getNombreMes(tmpInt).trim();
      fltMes.addValor(tmpInt, tmpString);
    }
    cr.close();

    listaFiltros.add(fltMes);

    DatosFiltro fltTipoDeporte = new DatosFiltro("Tipo deporte", "sportType");

    cr = getTiposDeporteDiferentes();

    while (cr.moveToNext()) {
      tmpInt = cr.getInt(0);
      tmpString = Utilidades.getSportType(tmpInt).trim();
      fltTipoDeporte.addValor(tmpInt, tmpString);
    }
    cr.close();

    listaFiltros.add(fltTipoDeporte);
  }
예제 #17
0
 private void gotoNext() {
   if (cursorLocation == stacks.length - 1) {
     cursorLocation = 0;
   } else {
     cursorLocation++;
   }
   cursor.setStack(stacks[cursorLocation]);
   // controller.alert("KeyCode:"+keyCode+"\nCursor:"+cursor.toString());
   repaint();
 }
예제 #18
0
 private void gotoPrevious() {
   if (cursorLocation == 0) {
     cursorLocation = stacks.length - 1;
   } else {
     cursorLocation--;
   }
   cursor.setStack(stacks[cursorLocation]);
   // controller.alert("KeyCode:"+keyCode+"\nCursor:"+cursor.toString());
   repaint();
 }
예제 #19
0
 public boolean next() throws SQLException {
   // TODO: for timeout, see IteratorResultSet.next
   if (cursor.next()) {
     ++row;
     return true;
   } else {
     afterLast = true;
     return false;
   }
 }
예제 #20
0
  // Cursors: arrow, cross, section, zoomIn, zoomOut;
  public void setCPCursor(Point p, boolean shiftDown) {
    if (isInDragArea(p)) {
      if (toolMode == Constants.ZOOM_MODE) {
        if (shiftDown) setCursor(zoomOut);
        else setCursor(zoomIn);
      } else if (toolMode == Constants.SELECT_MODE) {
        setCursor(cross);
      } else if (toolMode == Constants.SECTION_MODE) {
        setCursor(section);
      } else {
        setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
      }

      // display the cursor loc in real values
      displayCursorValues(p);
    } else if (isInDragArea(p) && Constants.ISMAC) {
      setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    } else setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }
예제 #21
0
  private void newView() {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = screenSize.width;
    int height = screenSize.height - 80;
    frame = new TerminalFrame(this);

    frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    frame.setSize(width, height);
    frame.centerFrame();
    frames.add(frame);
  }
예제 #22
0
  public boolean refreshBusquedaSelection(JInternalFrame frame, GeopistaEditor geopistaEditor) {

    try {

      frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

      geopistaEditor.getSelectionManager().clear();

      GeopistaLayer geopistaLayer =
          (GeopistaLayer) geopistaEditor.getLayerManager().getLayer(layerBusqueda);

      Enumeration enumerationElement = valoresBusqueda.keys();

      while (enumerationElement.hasMoreElements()) {
        String referenciaCatastral = (String) enumerationElement.nextElement();
        // El numero 1 identifica el id numero de policia
        Collection collection = searchByAttribute(geopistaLayer, 1, referenciaCatastral);
        Iterator it = collection.iterator();
        if (it.hasNext()) {
          Feature feature = (Feature) it.next();
          geopistaEditor.select(geopistaLayer, feature);
        }
      }

      geopistaEditor.zoomToSelected();
      frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      return true;
    } catch (Exception ex) {

      frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      ex.printStackTrace(pw);
      logger.error("Exception: " + sw.toString());
      return false;
    }
  }
예제 #23
0
  /** Creates a new <code>ColorPickerPanel</code> */
  public ColorPickerPanel() {
    setMaximumSize(
        new Dimension(
            MAX_SIZE + imagePadding.left + imagePadding.right,
            MAX_SIZE + imagePadding.top + imagePadding.bottom));
    setPreferredSize(new Dimension((int) (MAX_SIZE * .75), (int) (MAX_SIZE * .75)));

    setRGB(0, 0, 0);
    addMouseListener(mouseListener);
    addMouseMotionListener(mouseListener);

    setFocusable(true);
    addKeyListener(keyListener);
    addFocusListener(focusListener);

    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    addComponentListener(componentListener);
  }
예제 #24
0
 /** The constructor that defines the basic user interface and the mouse click handler. */
 DateLabel() {
   super("", CENTER);
   setToolTipText("Click to change.");
   setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
   addMouseListener(
       new MouseAdapter() {
         @Override
         public void mouseClicked(MouseEvent e) {
           DateChooser dc = new DateChooser(ReviewDialog.this, calendar);
           if (dc.showDateChooser() == DateChooser.OK_OPTION) {
             calendar = dc.getDate();
             resetYearWeekComboBoxes();
             refresh();
             refreshReviewTable();
           }
         }
       });
 }
예제 #25
0
  protected void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();

    // Create a green background
    g.setColor(tableColor);
    g.fillRect(0, 0, width, height);

    // Ask each stack to paint itself.
    // PlayStack
    for (int i = 0; i < stacks.length; i++) {
      stacks[i].paint(g);
    }

    // Draw some fancies
    g.setColor(0x00FFFFFF);
    g.drawLine(width / 2, marginTop, width / 2, marginTop + cardHeight);

    // Draw the cursor over the currently-selected stack
    cursor.paint(g);

    // Update the timer strip.
    timerStrip.paint(g);
  }
예제 #26
0
 public boolean wasNull() throws SQLException {
   return cursor.wasNull();
 }
예제 #27
0
 /**
  * Returns a cursor for the handle.
  *
  * @return Returns a move cursor, if the figure is transformable. Returns a default cursor
  *     otherwise.
  */
 @Override
 public Cursor getCursor() {
   return Cursor.getPredefinedCursor(
       getOwner().isTransformable() ? Cursor.MOVE_CURSOR : Cursor.DEFAULT_CURSOR);
 }
예제 #28
0
  /** INTERNAL: Conform the result if specified. */
  protected Object conformResult(
      Object result,
      UnitOfWorkImpl unitOfWork,
      AbstractRecord arguments,
      boolean buildDirectlyFromRows) {
    if (getSelectionCriteria() != null) {
      ExpressionBuilder builder = getSelectionCriteria().getBuilder();
      builder.setSession(unitOfWork.getRootSession(null));
      builder.setQueryClass(getReferenceClass());
    }

    // If the query is redirected then the collection returned might no longer
    // correspond to the original container policy.  CR#2342-S.M.
    ContainerPolicy cp;
    if (getRedirector() != null) {
      cp = ContainerPolicy.buildPolicyFor(result.getClass());
    } else {
      cp = getContainerPolicy();
    }

    // This code is now a great deal different...  For one, registration is done
    // as part of conforming.  Also, this should only be called if one actually
    // is conforming.
    // First scan the UnitOfWork for conforming instances.
    // This will walk through the entire cache of registered objects.
    // Let p be objects from result not in the cache.
    // Let c be objects from cache.
    // Presently p intersect c = empty set, but later p subset c.
    // By checking cache now doesConform will be called p fewer times.
    Map indexedInterimResult =
        unitOfWork.scanForConformingInstances(
            getSelectionCriteria(), getReferenceClass(), arguments, this);

    Cursor cursor = null;
    // In the case of cursors just conform/register the initially read collection.
    if (cp.isCursorPolicy()) {
      cursor = (Cursor) result;
      cp = ContainerPolicy.buildPolicyFor(ClassConstants.Vector_class);
      // In nested UnitOfWork session might have been session of the parent.
      cursor.setSession(unitOfWork);
      result = cursor.getObjectCollection();
      // for later incremental conforming...
      cursor.setInitiallyConformingIndex(indexedInterimResult);
      cursor.setSelectionCriteriaClone(getSelectionCriteria());
      cursor.setTranslationRow(arguments);
    }

    // Now conform the result from the database.
    // Remove any deleted or changed objects that no longer conform.
    // Deletes will only work for simple queries, queries with or's or anyof's may not return
    // correct results when untriggered indirection is in the model.
    Vector fromDatabase = null;

    // When building directly from rows, one of the performance benefits
    // is that we no longer have to wrap and then unwrap the originals.
    // result is just a vector, not a container of wrapped originals.
    if (buildDirectlyFromRows) {
      Vector rows = (Vector) result;
      fromDatabase = new Vector(rows.size());
      for (int i = 0; i < rows.size(); i++) {
        Object object = rows.elementAt(i);
        // null is placed in the row collection for 1-m joining to filter duplicate rows.
        if (object != null) {
          Object clone =
              conformIndividualResult(
                  object,
                  unitOfWork,
                  arguments,
                  getSelectionCriteria(),
                  indexedInterimResult,
                  buildDirectlyFromRows);
          if (clone != null) {
            fromDatabase.addElement(clone);
          }
        }
      }
    } else {
      fromDatabase = new Vector(cp.sizeFor(result));
      AbstractSession sessionToUse = unitOfWork.getParent();
      for (Object iter = cp.iteratorFor(result); cp.hasNext(iter); ) {
        Object object = cp.next(iter, sessionToUse);
        Object clone =
            conformIndividualResult(
                object,
                unitOfWork,
                arguments,
                getSelectionCriteria(),
                indexedInterimResult,
                buildDirectlyFromRows);
        if (clone != null) {
          fromDatabase.addElement(clone);
        }
      }
    }

    // Now add the unwrapped conforming instances into an appropriate container.
    // Wrapping is done automatically.
    // Make sure a vector of exactly the right size is returned.
    Object conformedResult =
        cp.containerInstance(indexedInterimResult.size() + fromDatabase.size());
    Object eachClone;
    for (Iterator enumtr = indexedInterimResult.values().iterator(); enumtr.hasNext(); ) {
      eachClone = enumtr.next();
      cp.addInto(eachClone, conformedResult, unitOfWork);
    }
    for (Enumeration enumtr = fromDatabase.elements(); enumtr.hasMoreElements(); ) {
      eachClone = enumtr.nextElement();
      cp.addInto(eachClone, conformedResult, unitOfWork);
    }

    if (cursor != null) {
      cursor.setObjectCollection((Vector) conformedResult);

      // For nested UOW must copy all in object collection to
      // initiallyConformingIndex, as some of these could have been from
      // the parent UnitOfWork.
      if (unitOfWork.isNestedUnitOfWork()) {
        for (Enumeration enumtr = cursor.getObjectCollection().elements();
            enumtr.hasMoreElements(); ) {
          Object clone = enumtr.nextElement();
          indexedInterimResult.put(clone, clone);
        }
      }
      return cursor;
    } else {
      return conformedResult;
    }
  }
예제 #29
0
  /**
   * INTERNAL: All objects queried via a UnitOfWork get registered here. If the query went to the
   * database.
   *
   * <p>Involves registering the query result individually and in totality, and hence refreshing /
   * conforming is done here.
   *
   * @param result may be collection (read all) or an object (read one), or even a cursor. If in
   *     transaction the shared cache will be bypassed, meaning the result may not be originals from
   *     the parent but raw database rows.
   * @param unitOfWork the unitOfWork the result is being registered in.
   * @param arguments the original arguments/parameters passed to the query execution. Used by
   *     conforming
   * @param buildDirectlyFromRows If in transaction must construct a registered result from raw
   *     database rows.
   * @return the final (conformed, refreshed, wrapped) UnitOfWork query result
   */
  public Object registerResultInUnitOfWork(
      Object result,
      UnitOfWorkImpl unitOfWork,
      AbstractRecord arguments,
      boolean buildDirectlyFromRows) {
    // For bug 2612366: Conforming results in UOW extremely slow.
    // Replacing results with registered versions in the UOW is a part of
    // conforming and is now done while conforming to maximize performance.
    if (shouldConformResultsInUnitOfWork()
        || this.descriptor.shouldAlwaysConformResultsInUnitOfWork()) {
      return conformResult(result, unitOfWork, arguments, buildDirectlyFromRows);
    }

    // When building directly from rows, one of the performance benefits
    // is that we no longer have to wrap and then unwrap the originals.
    // result is just a vector, not a collection of wrapped originals.
    // Also for cursors the initial connection is automatically registered.
    if (buildDirectlyFromRows) {
      List<AbstractRecord> rows = (List<AbstractRecord>) result;
      ContainerPolicy cp = getContainerPolicy();
      int size = rows.size();
      Object clones = cp.containerInstance(size);
      for (int index = 0; index < size; index++) {
        AbstractRecord row = rows.get(index);

        // null is placed in the row collection for 1-m joining to filter duplicate rows.
        if (row != null) {
          Object clone = buildObject(row);
          cp.addInto(clone, clones, unitOfWork, row, this);
        }
      }
      return clones;
    }

    ContainerPolicy cp;
    Cursor cursor = null;

    // If the query is redirected then the collection returned might no longer
    // correspond to the original container policy.  CR#2342-S.M.
    if (getRedirector() != null) {
      cp = ContainerPolicy.buildPolicyFor(result.getClass());
    } else {
      cp = getContainerPolicy();
    }

    // In the case of cursors just register the initially read collection.
    if (cp.isCursorPolicy()) {
      cursor = (Cursor) result;
      // In nested UnitOfWork session might have been session of the parent.
      cursor.setSession(unitOfWork);
      cp = ContainerPolicy.buildPolicyFor(ClassConstants.Vector_class);
      result = cursor.getObjectCollection();
    }

    Object clones = cp.containerInstance(cp.sizeFor(result));
    AbstractSession sessionToUse = unitOfWork.getParent();
    for (Object iter = cp.iteratorFor(result); cp.hasNext(iter); ) {
      Object object = cp.next(iter, sessionToUse);
      Object clone = registerIndividualResult(object, unitOfWork, this.joinedAttributeManager);
      cp.addInto(clone, clones, unitOfWork);
    }
    if (cursor != null) {
      cursor.setObjectCollection((Vector) clones);
      return cursor;
    } else {
      return clones;
    }
  }
  public SearchPatient(final String type, final int docID) {

    try {
      // "Load" the JDBC driver
      Class.forName("java.sql.Driver");

      // Establish the connection to the database
      String url = "jdbc:mysql://localhost:3306/cse";
      conn = DriverManager.getConnection(url, "root", "admin");
    } catch (Exception e) {
      System.err.println("Got an exception!");
      System.err.println(e.getMessage());
    }

    // Menu
    // MENU ACTIONS

    // Action to view new patient registered
    class NewPatientAction extends AbstractAction {
      private static final long serialVersionUID = 1L;

      public NewPatientAction() {
        putValue(SHORT_DESCRIPTION, "View list of new patients");
      }

      public void actionPerformed(ActionEvent e) {
        ViewRegisteredPatients vp = new ViewRegisteredPatients("new");
        vp.setVisible(true);
        ViewRegisteredPatients.hasNew = false;
      }
    }
    Action newPatientAction = new NewPatientAction();

    // Action to view all patient registered
    class AllPatientAction extends AbstractAction {
      private static final long serialVersionUID = 1L;

      public AllPatientAction() {
        putValue(SHORT_DESCRIPTION, "View list of all patients");
      }

      public void actionPerformed(ActionEvent e) {
        ViewRegisteredPatients vp = new ViewRegisteredPatients("all");
        vp.setVisible(true);
      }
    }
    Action allPatientAction = new AllPatientAction();

    // Action to open Statistical Report
    class StatsReportAction implements MenuListener {
      public void menuSelected(MenuEvent e) {
        StatsReport report = new StatsReport();
        setAlwaysOnTop(false);
        report.setVisible(true);
        report.setAlwaysOnTop(true);
      }

      public void menuDeselected(MenuEvent e) {}

      public void menuCanceled(MenuEvent e) {}
    }

    // Action to open Statistical Report
    class ProfileAction implements MenuListener {
      public void menuSelected(MenuEvent e) {
        Profile profilePage = new Profile("staff", docID, type);
        profilePage.setVisible(true);
        dispose();
      }

      public void menuDeselected(MenuEvent e) {}

      public void menuCanceled(MenuEvent e) {}
    }

    // MENU COMPONENTS
    menu = new JMenuBar();

    menuOp1 = new JMenu();
    menuOp2 = new JMenu();
    menuOp3 = new JMenu();
    menuOp4 = new JMenu();
    menuOp5 = new JMenu();

    menuOp1.setText("Profile");
    menuOp1.addMenuListener(new ProfileAction());

    optionsFrame = new JFrame("Options");

    optionsContainer = new JPanel();
    optionsContainer.setLayout(new BoxLayout(optionsContainer, BoxLayout.Y_AXIS));
    optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));

    if (type.equals("Doctor")) // if a doctor is logging in
    {
      menuOp2.setText("Patients");
      menuOp3.setText("Appointments Request");
      menuOp4.setText("View Medical Alerts");

      menuItem1 = new JMenuItem("Search Patient");

      menuOp2.add(menuItem1);

      menu.add(menuOp1);
      menu.add(menuOp2);
      menu.add(menuOp3);
      menu.add(menuOp4);

      // optionsFrame
      optionUpdateHCC = new JLabel("Update Healthcare Condition");
      optionUpdateHCC.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCC.addMouseListener(new MouseUpdateHCCListener());

      optionPrescription = new JLabel("e-Prescription");
      optionPrescription.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      // optionPrescription.addMouseListener(new MousePrescriptionListener());

      optionLabRecord = new JLabel("View Lab Records");
      optionLabRecord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionLabRecord.addMouseListener(new MouseLabRecordListener());

      optionUpdateHCR = new JLabel("Update Healthcare Records");
      optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener());

      // add option to container
      optionsContainer.add(optionUpdateHCC);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionPrescription);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionLabRecord);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionLabRecord);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionUpdateHCR);
    } else if (type.equals("HSP")) // if the HSP is logging in
    {
      menuOp2.setText("Patients");
      menuOp3.setText("Appointment Request");
      menuOp4.setText("View Medical Alerts");
      menuOp5.setText("Generate Statistical Report");
      menuOp5.addMenuListener(new StatsReportAction());

      menuItem1 = new JMenuItem("Search Patient");
      menuOp6 = new JMenu("List of Registered Patient");
      menuOp6.setMnemonic(KeyEvent.VK_S);

      menuItem2 = new JMenuItem(newPatientAction);
      menuItem2.setText("List of New Registered Patient");
      menuItem3 = new JMenuItem(allPatientAction);
      menuItem3.setText("List of All Registered Patient");

      menuOp2.add(menuItem1);
      menuOp2.add(menuOp6);
      menuOp6.add(menuItem2);
      menuOp6.add(menuItem3);

      menu.add(menuOp1);
      menu.add(menuOp2);
      menu.add(menuOp3);
      menu.add(menuOp4);
      menu.add(menuOp5);

      // optionsFrame
      optionUpdateHCC = new JLabel("Update Healthcare Condition");
      optionUpdateHCC.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCC.addMouseListener(new MouseUpdateHCCListener());

      optionLabRecord = new JLabel("View Lab Records");
      optionLabRecord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionLabRecord.addMouseListener(new MouseLabRecordListener());

      optionHCR = new JLabel("Upload Healthcare Records");
      optionHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionHCR.addMouseListener(new MouseUploadHCRListener());

      optionUpdateHCR = new JLabel("Update Healthcare Records");
      optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener());

      // add option to container
      optionsContainer.add(optionUpdateHCC);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionLabRecord);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionLabRecord);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionHCR);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionUpdateHCR);
    } else if (type.equals("Pharmacist")) // if the Pharmacist is logging in
    {
      menuOp2.setText("Patients");

      menuItem1 = new JMenuItem("Search Patients");

      menuOp2.add(menuItem1);

      menu.add(menuOp1);
      menu.add(menuOp2);

      // optionsFrame
      optionViewPrescription = new JLabel("View e-Prescription");
      optionViewPrescription.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionViewPrescription.addMouseListener(new MouseViewPrescriptionListener());

      // add option to container
      optionsContainer.add(optionViewPrescription);

    } else if (type.equals("Nurse")) // if the nurse is logging in
    {
      menuOp2.setText("Patients");

      menuItem1 = new JMenuItem("Search Patients");

      menuOp2.add(menuItem1);

      menu.add(menuOp1);
      menu.add(menuOp2);

      // optionsFrame
      optionUpdateHCR = new JLabel("Update Healthcare Records");
      optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener());

      // add option to container
      optionsContainer.add(optionUpdateHCR);
    }

    // Labels
    firstNameLabel = new JLabel(" First name:"); // first name label
    lastNameLabel = new JLabel("Last name:"); // last name label
    patientListLabel = new JLabel("Patient List:"); // patient list label

    // Text Fields
    firstNameField = new JTextField(10); // first name text field
    lastNameField = new JTextField(10); // last name text field

    // Buttons
    searchButton = new JButton("Search"); // search button
    searchButton.addActionListener(new SearchButtonListener()); // add listener

    selectButton = new JButton("Select");
    selectButton.addActionListener(new SelectButtonListener()); // add listener

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new CancelButtonListener()); // add listener

    // JPanels
    firstNamePanel = new JPanel(); // First name panel
    firstNamePanel.add(firstNameLabel);
    firstNamePanel.add(firstNameField);

    lastNamePanel = new JPanel(); // Last name panel
    lastNamePanel.add(lastNameLabel);
    lastNamePanel.add(lastNameField);

    patientInfoPanel = new JPanel();
    patientInfoPanel.setLayout(new BoxLayout(patientInfoPanel, BoxLayout.X_AXIS));
    patientInfoPanel.add(firstNamePanel);
    patientInfoPanel.add(lastNamePanel);
    patientInfoPanel.add(searchButton);

    buttonPanel = new JPanel(); // button panel
    buttonPanel.add(selectButton);
    buttonPanel.add(cancelButton);

    // Patient List
    patientVector = new Vector(); // Vector of Patient objects
    patientList =
        new JList(patientVector); // creates a JList that show the content of the recordVector

    scrollPatientList = new JScrollPane(patientList); // add scroll option to the list
    patientList.setSelectionMode(
        ListSelectionModel.SINGLE_SELECTION); // Allow the selection of only one item at a time

    String[] patients = new String[1000000];

    // Populates the patient list with the patients from the database
    if (type.equals("Doctor")) {
      int i = 0;
      try {
        // checks if the patient is a patient of the doctor logged
        statement = conn.createStatement();
        rs =
            statement.executeQuery(
                "SELECT * FROM appointments WHERE `docID`='" + docID + "' ORDER BY `patientID`");

        while (rs.next()) {
          int patientID = rs.getInt("patientID");
          patients[i] = String.valueOf(patientID);

          i++;
        }

        String[] patientSet =
            (String[]) new HashSet(Arrays.asList(patients)).toArray(new String[0]);

        // gets information from the specific set of patients
        for (int j = 0; j < patientSet.length; j++) {
          statement = conn.createStatement();
          rs =
              statement.executeQuery(
                  "SELECT * FROM patient WHERE `idpatient`='" + patientSet[j] + "';");

          while (rs.next()) {
            Patient obj = new Patient();
            obj.setFirstName(rs.getString("fname"));
            obj.setLastName(rs.getString("lname"));
            obj.setDOB(rs.getString("dob"));
            obj.setPatientId(Integer.parseInt(patientSet[j]));

            patientVector.add(obj);
          }
        }

      } catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
        System.err.println(e);
      }
    } else {
      try {
        statement = conn.createStatement();
        rs = statement.executeQuery("SELECT * FROM patient ORDER BY fname");

        while (rs.next()) {
          Patient obj = new Patient();
          obj.setFirstName(rs.getString("fname"));
          obj.setLastName(rs.getString("lname"));
          obj.setDOB(rs.getString("dob"));
          obj.setPatientId(rs.getInt("idpatient"));

          patientVector.add(obj);
        }
      } catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
      }
    }

    searchVector = new Vector();

    // set options frame
    optionsFrame.add(optionsContainer);
    optionsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // close the window on close
    optionsFrame.setSize(300, 150); // set size of window
    optionsFrame.setLocation(600, 280);
    optionsFrame.setVisible(false);

    searchPanel = new JPanel();
    searchPanel.setLayout(new BoxLayout(searchPanel, BoxLayout.Y_AXIS));
    searchPanel.add(patientInfoPanel);
    searchPanel.add(patientListLabel);
    searchPanel.add(scrollPatientList);
    searchPanel.add(buttonPanel);

    Border padding = BorderFactory.createEmptyBorder(20, 20, 10, 10);
    searchPanel.setBorder(padding);

    setJMenuBar(menu);
    add(searchPanel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(1200, 580);
  }