SWT - 变灰并禁用当前外壳 [英] SWT - Grey out and disable current shell

查看:36
本文介绍了SWT - 变灰并禁用当前外壳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在后台运行一个操作时,我将光标设置为忙碌,直到该过程完成.有没有办法在该过程完成之前也将当前的显示/对话框/外壳变灰并禁用.我想在视觉上让用户知道有些东西正在运行,他们必须等待.

When I have a operation running in the back ground, I am setting my cursor to busy until the process completes. Is there a way to also grey out and disable the current Display/Dialog/Shell until the process completes. I want to visually let the user know that something is working and they have to wait.

编辑

plotButton.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event arg0) {
         getShell().setEnabled(!getShell().getEnabled());
         getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT));    
         recursiveSetEnabled(getShell(), getShell().getEnabled());
         startPrinterListOperation(); <== This is method that runs operation
      }
  });

运行打印机操作的方法.

Method that runs a printer operation.

private void startPrinterListOperation() {
  listOp = new AplotPrinterListOperation(appReg.getString("aplot.message.GETPRINTERLIST"), session);
  listOp.addOperationListener(new MyOperationListener(this) {
     public void endOperationImpl() {
        try {
           printers.clear();
           printers.addAll((ArrayList<PrinterProfile>) listOp.getPrinters());
           Display.getDefault().asyncExec(new Runnable() {
              public void run() {
                showAplotPlotterDialog(); <== When operation returns - opens selection dialog
              }
           });
        }
        finally {

           listOp.removeOperationListener(this);
           listOp = null;
        }
     }
  });
  session.queueOperation(listOp);
} // end startPrinterListOperation()

showAplotPlotterDialog()(单独的类)打开一个与网络打印机的对话框,然后按下按钮将作业发送到选定的打印机.当该操作完成时,绘图仪对话框关闭 - 这是该方法的结束 - baseDialog 是主 GUI

showAplotPlotterDialog() (Seperate Class) opens a dialog with network printers, then with a button push sends a job to the selected printer. When that operation finishes the Plotter Dialog closes - This is the end of that method - baseDialog is the MAIN GUI

finally {
           plotOp.removeOperationListener(this);
           plotOp = null;
           Display.getDefault().asyncExec(new Runnable() {
              public void run() {
                baseDialog.removeAllTableRows();
                baseDialog.plotRequestCompleted = true;
                baseDialog.setResultsButtonVisibility();
                getShell().close();

              }
           });
        }

推荐答案

以下应该做你想做的.它会递归地禁用和灰显 Shell 中的所有 Control.Shell 本身没有 setGrayed 方法,但这会起作用:

The following should do what you want. It will recursively disable and grey out all the Controls in your Shell. The Shell itself does not have a setGrayed method, but this will work:

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Button");

    button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            shell.setEnabled(!shell.getEnabled());
            shell.setCursor(new Cursor(display, SWT.CURSOR_WAIT));      
            recursiveSetEnabled(shell, shell.getEnabled());
        }
    });

    new Text(shell, SWT.NONE).setText("TEXT");

    shell.setSize(400, 400);
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

private static void recursiveSetEnabled(Control control, boolean enabled) {
    if (control instanceof Composite)
    {
        Composite comp = (Composite) control;

        for (Control c : comp.getChildren())
            recursiveSetEnabled(c, enabled);
    }
    else
    {
        control.setEnabled(enabled);
    }
}

这篇关于SWT - 变灰并禁用当前外壳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆