SWT:无法找到Widget的源处理异常

时间:2014-03-06 21:56:52

标签: java widget swt dispose jface

我在关闭SWT对话框时遇到了小部件异常。我知道这告诉我,某些东西试图调用一个小部件,但是我无法找到这种情况发生的原因。以下是我的代码摘录:

final Display display = Display.getCurrent();
final Shell shell = new Shell(display, SWT.RESIZE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.APPLICATION_MODAL);
final ConstraintDialog dialog = new ConstraintDialog(shell);
dialog.open();

protected Control createDialogArea(final Composite parent) {
    final Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new RowLayout(SWT.VERTICAL));

    final Label lblSource = new Label(grpNewConstraint, SWT.NONE);
    lblSource.setFont(JFaceResources.getFontRegistry().getBold(""));
    lblSource.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    lblSource.setText("Source Feature");
    new Label(grpNewConstraint, SWT.NONE);

    final ListViewer lvConstraints = new ListViewer(grpExistingConstraints, SWT.V_SCROLL);
    lvConstraints.setContentProvider(new ConstraintDialogContentProvider());
    lvConstraints.setLabelProvider(new ConstraintDialogLabelProvider());
    lvConstraints.setInput(this.fm);
    final List listConstraints = lvConstraints.getList();
    final GridData gd_listConstraints = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
    gd_listConstraints.heightHint = 120;
    listConstraints.setLayoutData(gd_listConstraints);

    final Button btnAddConstraint = new Button(composite_Buttons, SWT.NONE);
    btnAddConstraint.setToolTipText("Use th form above to add a new Constraint");
    btnAddConstraint.setText("Add Constraint");
    btnAddConstraint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent event) {
                ..........
                lvConstraints.refresh();
                final Point grpSize = grpExistingConstraints.computeSize(SWT.DEFAULT, SWT.DEFAULT); 
                grpExistingConstraints.setSize(grpSize);
    ....
    });

这是错误堆栈,它根本没有帮助我找到错误的来源:

org.eclipse.swt.SWTException: Widget is disposed
    at org.eclipse.swt.SWT.error(SWT.java:4397)
    at org.eclipse.swt.SWT.error(SWT.java:4312)
    at org.eclipse.swt.SWT.error(SWT.java:4283)
    at org.eclipse.swt.widgets.Widget.error(Widget.java:472)
    at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:344)
    at org.eclipse.swt.widgets.Control.addFocusListener(Control.java:190)
    at org.eclipse.jface.viewers.DialogCellEditor$2.widgetSelected(DialogCellEditor.java:247)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4170)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1426)

如果我打开并关闭窗口小部件,则不会出现任何异常。但是当我打开对话框时,执行一些操作(使用按钮)并关闭它,显示异常

------------更新-------------------

由于您的评论,我已扩展了我的代码段:

public CellEditor createPropertyEditor(final Composite parent) {
        return new ExtendedDialogCellEditor(parent, getLabelProvider()) {
            @SuppressWarnings("synthetic-access")
            @Override
            protected Object openDialogBox(final Control cellEditorWindow) {
                final Display display = Display.getCurrent();
                final Shell shell = new Shell(display, SWT.RESIZE | SWT.CLOSE | SWT.MIN | SWT.MAX
                        | SWT.APPLICATION_MODAL);
                if (ConstraintPropertyDescriptor.this.object instanceof FeatureModel) {
                    final FeatureModel fm = (FeatureModel) ConstraintPropertyDescriptor.this.object;
                    final ConstraintDialog dialog = new ConstraintDialog(fm, shell);
                    dialog.open();
                }
                return null;
            }
        };
    }

0 个答案:

没有答案