Package com.googlecode.richrest.client

Examples of com.googlecode.richrest.client.Transfer


      public void actionPerformed(ActionEvent e) {
        if (getTransferModelSize() == 0) {
          JOptionPane.showMessageDialog(TransferPane.this, "没有任何传输项!", "中止", JOptionPane.WARNING_MESSAGE);
          return;
        }
        final Transfer execution = (Transfer)transportationList.getSelectedValue();
        if (execution == null) {
          JOptionPane.showMessageDialog(TransferPane.this, "请选择传输项!", "中止", JOptionPane.WARNING_MESSAGE);
          return;
        }
        if (! execution.isAbortable()) {
          JOptionPane.showMessageDialog(TransferPane.this, "此传输项不允许中止!", "中止", JOptionPane.WARNING_MESSAGE);
          return;
        }
        ThreadUtils.execute(new Runnable(){
          public void run() {
            try {
              execution.abort();
              JOptionPane.showMessageDialog(TransferPane.this, "中止传输项完成!", "中止", JOptionPane.INFORMATION_MESSAGE);
            } catch (Throwable t) {
              JOptionPane.showMessageDialog(TransferPane.this, "中止传输项失败! 原因: " + t.getMessage(), "中止", JOptionPane.WARNING_MESSAGE);
            }
          }
        });
      }
    });

    transportationList.getSelectionModel().addListSelectionListener(new ListSelectionListener(){

      public void valueChanged(ListSelectionEvent e) {
        final Transfer execution = (Transfer)transportationList.getSelectedValue();
        if (execution != null) {
          timeLabel.setText(new DecimalFormat("###,##0").format(System.currentTimeMillis() - execution.getTransferringTime().getTime()) + " ms");
        } else {
          timeLabel.setText("");
        }
        abortButton.setEnabled(execution != null && execution.isAbortable());
      }

    });

    final JButton resetButton = new JButton("刷新", Images.getIcon("refresh.gif"));
    resetButton.setToolTipText("刷新传输列表");
    toolBar.add(resetButton);
    resetButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        try {
          refreshTransferList();
          JOptionPane.showMessageDialog(TransferPane.this, "刷新传输列表成功!", "刷新", JOptionPane.INFORMATION_MESSAGE);
        } catch (Throwable t) {
          JOptionPane.showMessageDialog(TransferPane.this, "刷新传输列表失败! 原因: " + t.getMessage(), "刷新", JOptionPane.WARNING_MESSAGE);
        }
      }
    });
    transportationListener = new TransferDelegate(new TransferAdapter() {
      @Override
      public void onTransfer(TransferEvent event) {
        Transfer execution = event.getTransfer();
        if (! execution.isTransferred()) {
          synchronized (transportationModel) {
            if (! transportationModel.contains(execution))
              transportationModel.addElement(execution);
          }
        }
      }
      @Override
      public void onTransferred(TransferEvent event) {
        Transfer execution = event.getTransfer();
        synchronized (transportationModel) {
          transportationModel.removeElement(execution);
        }
      }
      @Override
View Full Code Here


    private static final long serialVersionUID = 1L;

    public Component getListCellRendererComponent(JList list, Object value,
        int index, boolean isSelected, boolean cellHasFocus) {
      super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      Transfer execution = (Transfer)value;
      if (execution.isTransferring())
        this.setIcon(enableIcon);
      else
        this.setIcon(disableIcon);
      this.setText("" + (index + 1) + ". " + execution.toString());
      return this;
    }
View Full Code Here

        if (getTransportationModelSize() == 0) {
          MessageDialog.openWarning(parent.getShell(), "中止",
              "没有任何传输项!");
          return;
        }
        final Transfer execution = getSelectedExecution();
        if (execution == null) {
          MessageDialog.openWarning(parent.getShell(), "中止",
              "请选择传输项!");
          return;
        }
        if (!execution.isAbortable()) {
          MessageDialog.openWarning(parent.getShell(), "中止",
              "此传输项不允许中止!");
          return;
        }
        try {
          execution.abort();
          MessageDialog.openInformation(parent.getShell(), "中止",
              "中止传输项成功!");
        } catch (Throwable t) {
          MessageDialog.openWarning(parent.getShell(), "中止",
              "中止传输项失败! 原因: " + t.getMessage());
        }
      }
    });
    ToolItem refreshItem = new ToolItem(toolBar, SWT.NONE);
    refreshItem.setImage(Images.getImage("refresh.gif"));
    refreshItem.setText("刷新");
    refreshItem.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        refreshTransportationList(true);
      }
    });
    executionList = new List(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    executionList.setBounds(0, 40, 484, 384);
    Label statusLabel = new Label(this, SWT.NONE);
    statusLabel.setImage(Images.getImage("time.gif"));
    statusLabel.setBounds(0, 424, 20, 20);
    final Label timeLabel = new Label(this, SWT.NONE);
    timeLabel.setBounds(20, 428, 200, 20);
    executionList.addSelectionListener(new SelectionAdapter(){
      public void widgetSelected(SelectionEvent e) {
        final Transfer execution = getSelectedExecution();
        if (execution != null) {
          Display.getDefault().asyncExec(new Runnable() {
            public void run() {
              abortItem.setEnabled(execution.isAbortable());
              timeLabel.setText(new DecimalFormat("###,##0").format(System.currentTimeMillis() - execution.getTransferringTime().getTime()) + " ms");
            }
          });
        } else {
          Display.getDefault().asyncExec(new Runnable() {
            public void run() {
              abortItem.setEnabled(false);
              timeLabel.setText("");
            }
          });
        }
      }
      public void widgetDefaultSelected(SelectionEvent e) {
        widgetSelected(e);
      }
    });
    transportationListener = new TransferAdapter() {
      @Override
      public void onTransfer(TransferEvent event) {
        final Transfer execution = event.getTransfer();
        if (!execution.isTransferred()) {
          synchronized (executions) {
            if (! executions.contains(execution)) {
              executions.add(execution);
              final int i = executions.size();
              Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                  executionList.add("(挂起) "
                      + i + ". "
                      + execution.toString());
                }
              });
            }
          }
        }
      }

      @Override
      public void onTransferred(TransferEvent event) {
        Transfer execution = event.getTransfer();
        synchronized (executions) {
          final int i = executions.indexOf(execution);
          if (i > -1 && i < executions.size()) {
            executions.remove(i);
            Display.getDefault().asyncExec(new Runnable() {
              public void run() {
                executionList.remove(i);
              }
            });
          }
        }
      }

      @Override
      public void onTransferring(final TransferEvent event) {
        final Transfer execution = event.getTransfer();
        synchronized (executions) {
          if (executions.contains(execution)) {
            final int i = executions.indexOf(execution);
            Display.getDefault().asyncExec(new Runnable() {
              public void run() {
                executionList.setItem(i, "(传输) " + (i + 1) + ". "
                    + execution.toString());
              }
            });
          }
        }
      }
View Full Code Here

TOP

Related Classes of com.googlecode.richrest.client.Transfer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.