Fórum Dificuldades com o JDK 8 #503051

01/12/2014

0

Senhores, boa tarde.
Estou tendo alguns problemas com a migração de uma aplicação para o Java 8 e gostaria muito da ajuda dos senhores para resolver esse problema.

Tenho um método:

  private boolean reload() {
    ArrayList data = dataLocator.getListOfData(inputControl.getValue());
    DefaultListModel model = new DefaultListModel();
    for(int i=0;i<data.size();i++)
      model.addElement(data.get(i));
    jlist.setModel(model);
    jlist.revalidate();
    jlist.repaint();
    if (data.size()>0)
      list.setSelectedIndex(0);
    return data.size()>0;
  }


Quando compilo a aplicação, tenho a seguinte mensagem:

warning: [unchecked] unchecked conversion
ArrayList <Object> data = dataLocator.getListOfData(inputControl.getValue());
required: ArrayList<Object>
found: ArrayList


Será que poderiam me ajudar por gentileza?
Desde já Obrigado.
Giliard Lourenço

Giliard Lourenço

Responder

Posts

01/12/2014

Ronaldo Lanhellas

Tente assim:

ArrayList <Object> data = (ArrayList <Object>) dataLocator.getListOfData(inputControl.getValue());
Responder

Gostei + 0

01/12/2014

Ronaldo Lanhellas

Tente assim:

ArrayList <Object> data = (ArrayList <Object>) dataLocator.getListOfData(inputControl.getValue());
Responder

Gostei + 0

01/12/2014

Giliard Lourenço

Poxa o brigado pela prontidão em ajudar colega mas ainda não funcionou.
Veja na imagem.
[img]http://arquivo.devmedia.com.br/forum/imagem/253627-20141201-145146.png[/img]
Responder

Gostei + 0

01/12/2014

Giliard Lourenço

A classe completa que contem o método é essa:

public final class AutoCompletitionListener extends KeyAdapter {

  /** data locator used to retrieve a list of data that starts with the data just typed */
  private AutoCompletitionDataLocator dataLocator = null;

  /** input control to listen for key press events */
  private AutoCompletitionInputControl inputControl = null;

  /** window that contains the list of data */
  private JWindow window = new JWindow();

  /** list of data */
  private JList list = new JList();

  /** list container */
  private final JScrollPane scrollPane = new JScrollPane(list);

  /** time when occours last key pressed event */
  private long time = 0;

  /** wait time before showing data list (expressed in ms) */
  private final long waitTime;

  /** wait timer */
  private WaitTimer timer = null;


  /**
   * Constructor invoked from some input control of type text/number.
   * @param inputControl input control to listen for key press events
   * @param dataLocator data locator used to retrieve a list of data that starts with the data just typed
   * @param waitTime wait time before showing data list (expressed in ms)
   */
  public AutoCompletitionListener(AutoCompletitionInputControl inputControl,AutoCompletitionDataLocator dataLocator,long waitTime) {
    this.inputControl = inputControl;
    this.dataLocator = dataLocator;
    this.waitTime = waitTime;
    scrollPane.getViewport().setOpaque(false);
    scrollPane.setOpaque(false);
    list.setOpaque(false);
    list.setBackground(new Color(250,250,200));
    window.getContentPane().setBackground(new Color(250,250,200));
    scrollPane.getVerticalScrollBar().setFocusable(true);
      for (Component component : scrollPane.getVerticalScrollBar().getComponents()) {
          if (component instanceof JButton) {
              component.addMouseListener(new MouseAdapter() {
                  @Override
                  public void mousePressed(MouseEvent e) {
                      //        e.consume();
                      window.setVisible(true);
                  }
                  @Override
                  public void mouseClicked(MouseEvent e) {
                      e.consume();
                  }
                  @Override
                  public void mouseReleased(MouseEvent e) {
                      e.consume();
                  }
              });
          }
      }
    scrollPane.getVerticalScrollBar().addMouseListener(new MouseAdapter() {
      @Override
      public void mousePressed(MouseEvent e) {
//        e.consume();
        window.setVisible(true);
      }
      @Override
      public void mouseClicked(MouseEvent e) {
        e.consume();
      }
      @Override
      public void mouseReleased(MouseEvent e) {
        e.consume();
      }
    });
    window.setBackground(new Color(250,250,200));
    window.getContentPane().setLayout(new BorderLayout());
    window.getContentPane().add(scrollPane,BorderLayout.CENTER);

    list.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
          list.setSelectedIndex(list.locationToIndex(e.getPoint()));
          e.consume();
          AutoCompletitionListener.this.inputControl.setValue(list.getSelectedValue());
          window.setVisible(false);
          if (AutoCompletitionListener.this.inputControl instanceof CodLookupControl)
            ((CodLookupControl)AutoCompletitionListener.this.inputControl).getCodBox().forceValidate();
          if (AutoCompletitionListener.this.inputControl instanceof CodLookupCellEditor)
            ((CodLookupCellEditor)AutoCompletitionListener.this.inputControl).forceValidate();
          try {
            if (timer != null)
              timer.interrupt();
          }
          catch (Exception ex) {
          }
          time = 0;
        }
    });

    inputControl.addAncestorListener(new AncestorListener() {

      @Override
      public void ancestorAdded(AncestorEvent event) {
      }

      @Override
      public void ancestorMoved(AncestorEvent event) {
      }

      @Override
      public void ancestorRemoved(AncestorEvent event) {
        try {
          if (timer != null)
            timer.interrupt();
        }
        catch (Exception ex) {
        }
        window.setVisible(false);
        window.dispose();
      }

    });

    inputControl.addFocusListener(new FocusAdapter() {

      /**
       * Invoked when a component loses the keyboard focus.
       */
      @Override
      public void focusLost(final FocusEvent e) {
//        if (e.getOppositeComponent()!=null &&
//            e.getOppositeComponent().equals(window)) {
//          // user has clicked onto the scrollpane...
//          SwingUtilities.invokeLater(new Runnable() {
//            public void run() {
//              window.toFront();
//            }
//          });
//          return;
//        }
        window.setVisible(false);
        try {
          if (timer != null)
            timer.interrupt();
        }
        catch (Exception ex) {
        }
      }

    });

  }


  /**
   * @return <code>true</code> if window for autocompletition codes is currently visible, <code>false</code> otherwise
   */
  public final boolean isWindowVisible() {
    return window.isVisible();
  }


  @Override
  public final void keyPressed(KeyEvent e) {
    if (e.getKeyCode()==KeyEvent.VK_ENTER && window.isVisible() && list.getSelectedIndex()!=-1) {
      e.consume();
      inputControl.setValue(list.getSelectedValue());
      window.setVisible(false);
      if (inputControl instanceof CodLookupControl)
        ((CodLookupControl)inputControl).getCodBox().forceValidate();
      if (inputControl instanceof CodLookupCellEditor)
        ((CodLookupCellEditor)inputControl).forceValidate();
      try {
        if (timer != null)
          timer.interrupt();
      }
      catch (Exception ex) {
      }
      time = 0;
    }
    else if (e.getKeyCode()==KeyEvent.VK_UP && window.isVisible()) {
      if (list.getSelectedIndex()==-1)
        list.setSelectedIndex(0);
      else if (list.getSelectedIndex()==0)
        list.setSelectedIndex(list.getModel().getSize()-1);
      else
        list.setSelectedIndex(list.getSelectedIndex()-1);
      list.ensureIndexIsVisible(list.getSelectedIndex());
    }
    else if (e.getKeyCode()==KeyEvent.VK_DOWN && window.isVisible()) {
      if (list.getSelectedIndex()==-1)
        list.setSelectedIndex(0);
      else if (list.getSelectedIndex()<list.getModel().getSize()-1)
        list.setSelectedIndex(list.getSelectedIndex()+1);
      else
        list.setSelectedIndex(0);
      list.ensureIndexIsVisible(list.getSelectedIndex());
    }
    else if (e.getKeyCode()==KeyEvent.VK_ESCAPE || e.getKeyCode()==KeyEvent.VK_TAB) {
      window.setVisible(false);
      try {
        if (timer != null)
          timer.interrupt();
      }
      catch (Exception ex) {
      }
      time = 0;
    }
  }


  @Override
  public final void keyReleased(KeyEvent e) {
    if (e.getKeyCode()==KeyEvent.VK_ENTER || e.getKeyCode()==KeyEvent.VK_UP || e.getKeyCode()==KeyEvent.VK_DOWN || e.getKeyCode()==e.VK_ESCAPE)
      return;
    if (time==0) {
      time = System.currentTimeMillis();
      timer = new WaitTimer();
      timer.start();
    }
    else if (System.currentTimeMillis()-time<waitTime) {
      try {
        if (timer != null)
          timer.interrupt();
      }
      catch (Exception ex) {
      }
      timer = new WaitTimer();
      timer.start();
      time = System.currentTimeMillis();
      if (inputControl.getValue()==null || "".equals(inputControl.getValue().toString())) {
        window.setVisible(false);
        try {
          if (timer != null)
            timer.interrupt();
        }
        catch (Exception ex) {
        }
        time = 0;
      }
      else if (window.isVisible())
        checkInputControlValue();
    }
    else {
//      checkInputControlValue();
      time = System.currentTimeMillis();
    }
  }


  private void checkInputControlValue() {
//    else if (e.getKeyCode()==e.VK_ENTER) {
//      e.consume();
//      window.setVisible(false);
//      time = 0;
//    }
    if (inputControl.getValue()==null || "".equals(inputControl.getValue().toString())) {
      window.setVisible(false);
      try {
        if (timer != null)
          timer.interrupt();
      }
      catch (Exception ex) {
      }
      time = 0;
    }
    else if (!window.isVisible()) {
      window.setLocation(
        inputControl.getLocationOnScreen().x,
        inputControl.getLocationOnScreen().y+inputControl.getHeight()+1
      );
      if (reload()) {
        window.setSize(inputControl.getWidth(),200);
        window.setVisible(true);
      }
    }
    else {
      if (!reload()) {
        window.setVisible(false);
        try {
          if (timer != null)
            timer.interrupt();
        }
        catch (Exception ex) {
        }
        time = 0;
      }
    }
  }


  private boolean reload() {
    ArrayList <Object> data = (ArrayList <Object>)dataLocator.getListOfData(inputControl.getValue());
    DefaultListModel model = new DefaultListModel();
    for(int i=0;i<data.size();i++)
      model.addElement(data.get(i));
    list.setModel(model);
    list.revalidate();
    list.repaint();
    if (data.size()>0)
      list.setSelectedIndex(0);
    return data.size()>0;
  }


  /**
   * <p>Title: OpenSwing Framework</p>
   * <p>Description: Timer</p>
   * <p>Copyright: Copyright (C) 2008 Mauro Carniel</p>
   * @version 1.0
   */
  class WaitTimer extends Thread {

    @Override
    public void run() {
      try {
        sleep(waitTime);
        SwingUtilities.invokeLater(() -> {
            checkInputControlValue();
        });
      }
      catch (InterruptedException ex) {
      }
    }

  }


}
Responder

Gostei + 0

01/12/2014

Ronaldo Lanhellas

Tente colocar a seguinte anotação em cima do método:

@SuppressWarnings("unchecked")
Responder

Gostei + 0

01/12/2014

Ronaldo Lanhellas

Tente colocar a seguinte anotação em cima do método:

@SuppressWarnings("unchecked")
Responder

Gostei + 0

01/12/2014

Giliard Lourenço

Ok deu certo.
Obrigadão mesmo.
Responder

Gostei + 0

02/12/2014

Ronaldo Lanhellas

Ok deu certo.
Obrigadão mesmo.


De nada.
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar