@Override
  public boolean applyCSSProperty(
      Object element, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    Widget widget = SWTElementHelpers.getWidget(element);
    if (widget instanceof CTabItem) {
      Item item = (Item) widget;
      boolean showClose = ((Boolean) engine.convert(value, Boolean.class, null)).booleanValue();
      if ("selected".equals(pseudo)) {
        Control parent = getParent(widget);

        ShowCloseSelectionListener listener =
            (ShowCloseSelectionListener)
                parent.getData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY);
        if (listener == null) {
          listener = new ShowCloseSelectionListener(engine);
          parent.addListener(SWT.Paint, listener);
          parent.setData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY, listener);
        } else {
          listener.setEngine(engine);
        }
        item = getSelection(getParent(widget));

        listener.setSelection(item);
        if (item != null) {
          setShowClose(item, showClose);
        }
      } else {
        setShowClose(item, showClose);
      }
      return true;
    }
    return false;
  }
 private void onDispose() {
   if (control == null) return;
   this.Release();
   if (controlListener != null) {
     control.removeListener(SWT.Dispose, controlListener);
     control.removeListener(SWT.DragDetect, controlListener);
   }
   controlListener = null;
   control.setData(DND.DRAG_SOURCE_KEY, null);
   control = null;
   transferAgents = null;
 }
  /**
   * Creates a new <code>DragSource</code> to handle dragging from the specified <code>Control
   * </code>. Creating an instance of a DragSource may cause system resources to be allocated
   * depending on the platform. It is therefore mandatory that the DragSource instance be disposed
   * when no longer required.
   *
   * @param control the <code>Control</code> that the user clicks on to initiate the drag
   * @param style the bitwise OR'ing of allowed operations; this may be a combination of any of
   *     DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
   *       <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
   *     </ul>
   *
   * @exception SWTError
   *     <ul>
   *       <li>ERROR_CANNOT_INIT_DRAG - unable to initiate drag source; this will occur if more than
   *           one drag source is created for a control or if the operating system will not allow
   *           the creation of the drag source
   *     </ul>
   *     <p>NOTE: ERROR_CANNOT_INIT_DRAG should be an SWTException, since it is a recoverable error,
   *     but can not be changed due to backward compatibility.
   * @see Widget#dispose
   * @see DragSource#checkSubclass
   * @see DND#DROP_NONE
   * @see DND#DROP_COPY
   * @see DND#DROP_MOVE
   * @see DND#DROP_LINK
   */
  public DragSource(Control control, int style) {
    super(control, checkStyle(style));
    this.control = control;
    if (control.getData(DND.DRAG_SOURCE_KEY) != null) {
      DND.error(DND.ERROR_CANNOT_INIT_DRAG);
    }
    control.setData(DND.DRAG_SOURCE_KEY, this);
    createCOMInterfaces();
    this.AddRef();

    controlListener =
        new Listener() {
          public void handleEvent(Event event) {
            if (event.type == SWT.Dispose) {
              if (!DragSource.this.isDisposed()) {
                DragSource.this.dispose();
              }
            }
            if (event.type == SWT.DragDetect) {
              if (!DragSource.this.isDisposed()) {
                DragSource.this.drag(event);
              }
            }
          }
        };
    control.addListener(SWT.Dispose, controlListener);
    control.addListener(SWT.DragDetect, controlListener);

    this.addListener(
        SWT.Dispose,
        new Listener() {
          public void handleEvent(Event e) {
            DragSource.this.onDispose();
          }
        });

    Object effect = control.getData(DEFAULT_DRAG_SOURCE_EFFECT);
    if (effect instanceof DragSourceEffect) {
      dragEffect = (DragSourceEffect) effect;
    } else if (control instanceof Tree) {
      dragEffect = new TreeDragSourceEffect((Tree) control);
    } else if (control instanceof Table) {
      dragEffect = new TableDragSourceEffect((Table) control);
    }
  }
Example #4
0
 private void setCssName(final Control control) {
   control.setData(CSSSWTConstantsHelper.getCSS(), "editComposite"); // $NON-NLS-1$
 }