Ejemplo n.º 1
0
  @Test
  public void testDipose_CalledOnControlDispose() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);

    text.dispose();

    verify(remoteObject).destroy();
  }
 private void remove() {
   if (label != null && !label.isDisposed()) {
     label.dispose();
   }
   if (text != null && !text.isDisposed()) {
     text.dispose();
   }
 }
Ejemplo n.º 3
0
 /**
  * Toggles the unfolding of the details area. This is triggered by the user pressing the details
  * button.
  */
 private void toggleDetailsArea() {
   Point windowSize = getShell().getSize();
   Point oldSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT);
   if (text != null) {
     text.dispose();
     text = null;
     getButton(detailButtonID).setText(IDialogConstants.SHOW_DETAILS_LABEL);
   } else {
     createDropDownText((Composite) getContents());
     getButton(detailButtonID).setText(IDialogConstants.HIDE_DETAILS_LABEL);
   }
   Point newSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT);
   getShell().setSize(new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y)));
 }
Ejemplo n.º 4
0
  private void showControl(boolean show) {
    if (show && text == null) {
      caseSensitive = new Button(this, SWT.CHECK);
      caseSensitive.setText("Aa");
      caseSensitive.setToolTipText("Case Sensitive");
      GridData layoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
      caseSensitive.setLayoutData(layoutData);

      text = new Text(this, SWT.SINGLE | SWT.BORDER | SWT.FILL);
      layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
      text.setLayoutData(layoutData);
    }
    if (!show && text != null) {
      text.dispose();
      text = null;
      caseSensitive.dispose();
      caseSensitive = null;
    }
  }
  /**
   * Tests the bindings are properly disposed - both the primary binding and any additional bindings
   */
  @Test
  public void testControlDispose() {
    final IBindingContext context = IBindingContext.Factory.createContext(myView.getScrolledForm());

    final IValueBinding binding1 =
        context.addBinding(myText, myShop, IMOAOPackage.Literals.NAMED_OBJECT__NAME);
    final IValueBinding binding2 =
        context.addBinding().ui(myText, Constants.ATTR_ENABLED).model(myBoolOV);
    context.finish();
    yield();

    assertEquals(BindingState.OK, binding1.getState());
    assertEquals(BindingState.OK, binding2.getState());

    myText.dispose();
    yield();

    assertEquals(BindingState.DISPOSED, binding1.getState());
    assertEquals(BindingState.DISPOSED, binding2.getState());
  }
Ejemplo n.º 6
0
  /**
   * Add a new (SQL) Execution Tab
   *
   * @param AbstractSQLExecution
   */
  public void addSQLExecution(AbstractSQLExecution sqlExecution) {

    if (_tabFolder == null || _tabFolder.isDisposed()) {

      clearParent();

      // create tab folder for different sessions
      _tabFolder = new TabFolder(_parent, SWT.NULL);

      _parent.layout();
      _parent.redraw();
    }

    // create tab
    _lastTabNumber = _lastTabNumber + 1;
    final TabItem tabItem = new TabItem(_tabFolder, SWT.NULL);

    // set tab text & tooltip
    String labelText = "" + _lastTabNumber;
    tabItem.setText(labelText);
    tabItem.setData("tabLabel", labelText);
    tabItem.setToolTipText(TextUtil.getWrappedText(sqlExecution.getSqlStatement()));

    // create composite for our result
    Composite composite = new Composite(_tabFolder, SWT.NULL);

    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginLeft = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 0;

    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    tabItem.setControl(composite);
    tabItem.setData(sqlExecution);

    tabItem.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(final DisposeEvent e) {

            BusyIndicator.showWhile(
                Display.getCurrent(),
                new Runnable() {

                  public void run() {

                    // stop all sql execution if still running
                    TabItem tabItem = (TabItem) e.getSource();
                    AbstractSQLExecution sqlExecution = (AbstractSQLExecution) tabItem.getData();
                    sqlExecution.stop();
                    tabItem.setData(null);

                    if (_tabFolder != null && !_tabFolder.isDisposed()) {

                      if (_tabFolder.getItemCount() == 0) {
                        // this is last tab..
                        clearParent();
                        setDefaultMessage();
                      }

                    } else if (_tabFolder.isDisposed()) {
                      clearParent();
                      setDefaultMessage();
                    }
                  }
                });
          }
        });

    // add sql statement, first create temp label to calculate correct size

    String sqlStatement = sqlExecution.getSqlStatement();

    int labelHeight = 60;
    int labelStyle = SWT.WRAP | SWT.MULTI;

    Text tmpLabel = new Text(composite, labelStyle);
    tmpLabel.setText(TextUtil.removeLineBreaks(sqlExecution.getSqlStatement()));
    tmpLabel.setLayoutData(new FillLayout());
    int parentWidth = _parent.getClientArea().width;
    Point idealSize = tmpLabel.computeSize(parentWidth - 30, SWT.DEFAULT);

    if (idealSize.y <= 60) {
      // we don't need a scroll bar. minimize
      labelHeight = idealSize.y;
    } else {
      // we need a scroll bar
      labelStyle = SWT.WRAP | SWT.MULTI | SWT.V_SCROLL;
    }

    tmpLabel.dispose();

    // now create real label
    // create spanned cell for table data

    Composite headerComposite = new Composite(composite, SWT.FILL);
    headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    GridLayout hLayout = new GridLayout();
    hLayout.numColumns = 2;
    hLayout.marginLeft = 0;
    hLayout.horizontalSpacing = 0;
    hLayout.verticalSpacing = 0;
    hLayout.marginWidth = 0;
    hLayout.marginHeight = 0;

    headerComposite.setLayout(hLayout);

    Text label = new Text(headerComposite, labelStyle);
    label.setEditable(false);
    label.setBackground(_parent.getBackground());
    label.setText(TextUtil.removeLineBreaks(sqlStatement));
    label.setToolTipText(TextUtil.getWrappedText(sqlStatement));

    GridData labelGridData = new GridData(SWT.FILL, SWT.TOP, true, false);
    labelGridData.heightHint = labelHeight;
    label.setLayoutData(labelGridData);

    // add action bar

    ToolBarManager toolBarMgr = new ToolBarManager(SWT.FLAT);
    toolBarMgr.createControl(headerComposite);
    toolBarMgr.add(new CloseSQLResultTab(tabItem));
    toolBarMgr.update(true);
    GridData gid = new GridData();
    gid.horizontalAlignment = SWT.RIGHT;
    gid.verticalAlignment = SWT.TOP;
    toolBarMgr.getControl().setLayoutData(gid);

    // add detail composite to show progress bar and results
    Composite detailComposite = new Composite(composite, SWT.FILL);
    detailComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    sqlExecution.setComposite(detailComposite);
    sqlExecution.setParentTab(tabItem);
    sqlExecution.startExecution();

    // set new tab as the active one
    _tabFolder.setSelection(_tabFolder.getItemCount() - 1);

    // refresh view
    composite.layout();
    _tabFolder.layout();
    _tabFolder.redraw();

    // bring this view to top of the view stack
    getSite().getPage().bringToTop(this);
  }