org.eclipse.swt.widgets.Listener Java Examples

The following examples show how to use org.eclipse.swt.widgets.Listener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridToolTip.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
   * Creates an inplace tooltip.
   *
   * @param parent parent control.
   */
  public GridToolTip(final Control parent)
  {
      super(parent, SWT.NONE);

      shell = new Shell(parent.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
      shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
      shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));

      parent.addListener(SWT.Dispose, new Listener()
      {
	public void handleEvent(Event arg0)
	{
		shell.dispose();
		dispose();
	}
});

      shell.addListener(SWT.Paint, new Listener()
      {
          public void handleEvent(Event e)
          {
              onPaint(e.gc);
          }
      });
  }
 
Example #2
Source File: DefaultParameterDialogControlTypeHelper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void createContent( Composite parent )
{
	controlTypeChooser = new Combo( parent, SWT.READ_ONLY | SWT.DROP_DOWN );
	controlTypeChooser.setVisibleItemCount( 30 );
	controlTypeChooser.addListener( SWT.Selection, new Listener( ) {

		public void handleEvent( Event e )
		{
			List<Listener> listeners = DefaultParameterDialogControlTypeHelper.this.listeners.get( SWT.Selection );
			if ( listeners == null )
				return;
			for ( int i = 0; i < listeners.size( ); i++ )
				listeners.get( i ).handleEvent( e );
		}
	} );
}
 
Example #3
Source File: TextAssist.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @return a listener for the FocusOut event
 */
private Listener createFocusOutListener() {
	return new Listener() {
		@Override
		public void handleEvent(final Event event) {
			/*
			 * Async is needed to wait until focus reaches its new Control
			 */
			TextAssist.this.getDisplay().asyncExec(() -> {
				if (TextAssist.this.isDisposed() || TextAssist.this.getDisplay().isDisposed()) {
					return;
				}
				final Control control = TextAssist.this.getDisplay().getFocusControl();
				if (control == null || control != text && control != table) {
					popup.setVisible(false);
				}
			});
		}
	};
}
 
Example #4
Source File: PyConfigureExceptionDialog.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Initialises this dialog's viewer after it has been laid out.
 */
private void initContent() {
    listViewer.setInput(inputElement);
    Listener listener = new Listener() {
        @Override
        public void handleEvent(Event e) {
            if (updateInThread) {
                if (filterJob != null) {
                    // cancel it if it was already in progress
                    filterJob.cancel();
                }
                filterJob = new FilterJob();
                filterJob.start();
            } else {
                doFilterUpdate(new NullProgressMonitor());
            }
        }
    };

    filterPatternField.setText(filterPattern != null ? filterPattern : "");
    filterPatternField.addListener(SWT.Modify, listener);
}
 
Example #5
Source File: Breadcrumb.java    From SWET with MIT License 6 votes vote down vote up
private void addMouseDownListener() {
	addListener(SWT.MouseDown, new Listener() {
		@Override
		public void handleEvent(final Event event) {
			for (final BreadcrumbItem item : Breadcrumb.this.items) {
				if (item.getBounds().contains(event.x, event.y)) {
					final boolean isToggle = (item.getStyle() & SWT.TOGGLE) != 0;
					final boolean isPush = (item.getStyle() & SWT.PUSH) != 0;
					if (isToggle || isPush) {
						item.setSelection(!item.getSelection());
						redraw();
						update();
					}
					item.setData(IS_BUTTON_PRESSED, "*");
					return;
				}
			}
		}
	});
}
 
Example #6
Source File: FindReplaceDialog.java    From pmTrans with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void renderTransparency(final Shell shell) {
	Group group = new Group(shell, SWT.NONE);
	group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 6, 1));
	group.setLayout(new GridLayout(1, false));
	group.setText("Transparency");
	final Scale transparencySlider = new Scale(group, SWT.HORIZONTAL);
	transparencySlider.setMinimum(20);
	transparencySlider.setMaximum(100);
	transparencySlider.setPageIncrement(90);
	transparencySlider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
	transparencySlider.setSelection(100);
	transparencySlider.addListener(SWT.Selection, new Listener() {

		@Override
		public void handleEvent(Event event) {
			shell.setAlpha(255 * transparencySlider.getSelection() / 100);
		}
	});
}
 
Example #7
Source File: OutputParametersMappingSection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private CCombo createSubprocessSourceCombo(final Composite outputMappingControl, final OutputMapping mapping) {
    final CCombo subprocessSourceCombo = getWidgetFactory().createCCombo(outputMappingControl, SWT.BORDER);
    for (final Data subprocessData : callActivityHelper.getCallActivityData()) {
        subprocessSourceCombo.add(subprocessData.getName());
    }
    subprocessSourceCombo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(15, 0).create());
    subprocessSourceCombo.addListener(SWT.Modify, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            getEditingDomain().getCommandStack()
                    .execute(
                            new SetCommand(getEditingDomain(), mapping,
                                    ProcessPackage.Literals.OUTPUT_MAPPING__SUBPROCESS_SOURCE, subprocessSourceCombo
                                            .getText()));
        }
    });
    if (mapping.getSubprocessSource() != null) {
        subprocessSourceCombo.setText(mapping.getSubprocessSource());
    }
    return subprocessSourceCombo;
}
 
Example #8
Source File: SingleChoiceQuestionView.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected List<Control> renderControls() {
    List<Control> controls = new LinkedList<>();
    for (String choice : question.getChoices()) {
        Button btn = new Button(root, SWT.RADIO);
        btn.setText(choice);
        btn.setSelection(choice.equals(question.getAnswer(document)));
        btn.addListener(SWT.Selection, new Listener() {
			@Override
			public void handleEvent(Event event) {
                question.addAnswer(document, choice);
                onQuestionChanged.accept(question);
            }
        });
        controls.add(btn);
    }
    return controls;
}
 
Example #9
Source File: BidiLayout.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void addAndReorderListener(int eventType, Listener listener){
	//have to 'reorder' listeners in eventTable. BidiLayout's listener should come first (before StyledText's one)
	Listener[] listeners = styledText.getListeners(eventType);
	Listener styledTextListener = null;
	for (Listener listener2 : listeners) {
		if (listener2.getClass().getSimpleName().startsWith("StyledText")){
			styledTextListener = listener2;
			break;
		}
	}
	if (styledTextListener != null){
		styledText.removeListener(eventType, styledTextListener);
	}
	styledText.addListener(eventType, listener);
	if (styledTextListener != null){
		styledText.addListener(eventType, styledTextListener);
	}
}
 
Example #10
Source File: HyperlinkBuilder.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void createExpressionButton( Composite parent, final Text text )
{
	Listener listener = new Listener( ) {

		public void handleEvent( Event event )
		{
			updateButtons( );
		}

	};
	ExpressionButtonUtil.createExpressionButton( parent,
			text,
			getExpressionProvider( ),
			inputHandle.getElementHandle( ),
			listener );
}
 
Example #11
Source File: Bubble.java    From swt-bling with MIT License 6 votes vote down vote up
private void attachListeners() {
  listener = new Listener() {
    public void handleEvent(Event event) {
      switch (event.type) {
        case SWT.Paint:
          onPaint(event);
          break;
        case SWT.MouseDown:
          onMouseDown(event);
          break;
        case SWT.MouseEnter:
          BubbleRegistrant registrant = BubbleRegistry.getInstance().findRegistrant(getPoppedOverItem().getControlOrCustomElement());
          registrant.dismissBubble();
          registrant.bubble.setDisableAutoHide(false);
          break;
        default:
          break;
      }
    }
  };
  popOverShell.addListener(SWT.Paint, listener);
  popOverShell.addListener(SWT.MouseDown, listener);
  popOverShell.addListener(SWT.MouseEnter, listener);

  addAccessibilityHooks(parentControl);
}
 
Example #12
Source File: Resources.java    From arx with Apache License 2.0 6 votes vote down vote up
/**
 * Loads an image. Adds a dispose listener that disposes the image when the display is disposed
 * @param display
 * @param resource
 * @return
 */
private static final Image getImage(Display display, String resource) {
    InputStream stream = Resources.class.getResourceAsStream(resource);
    try {
        final Image image = new Image(display, stream);
        display.addListener(SWT.Dispose, new Listener() {
            public void handleEvent(Event arg0) {
                if (image != null && !image.isDisposed()) {
                    image.dispose();
                }
            }
        });
        return image;
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                // Ignore silently
            }
        }
    }
}
 
Example #13
Source File: GridToolTip.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
   * Creates an inplace tooltip.
   *
   * @param parent parent control.
   */
  public GridToolTip(final Control parent)
  {
      super(parent, SWT.NONE);

      shell = new Shell(parent.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
      shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
      shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));

      parent.addListener(SWT.Dispose, new Listener()
      {
	public void handleEvent(Event arg0)
	{
		shell.dispose();
		dispose();
	}
});

      shell.addListener(SWT.Paint, new Listener()
      {
          public void handleEvent(Event e)
          {
              onPaint(e.gc);
          }
      });
  }
 
Example #14
Source File: DisposalTests.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void testDisposeWithListeners() throws Exception {
	asyncExec(new Runnable() {
		public void run() {
			comp.addListener(SWT.Dispose, new Listener() {
				public void handleEvent(Event event) {
					assertFalse(comp.isDisposed());
				}
			});
		}
	});
	
	asyncExec(new Runnable() {
		public void run() {
			getShell().dispose();
		}
	});
	
	while(getDisplay() != null && !getDisplay().isDisposed()) {
		Thread.sleep(100);
	}
}
 
Example #15
Source File: ObservableCombo.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
public ObservableCombo(Composite parent, GridData gridData) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    
	combo = new Combo(container, SWT.READ_ONLY);
	combo.setLayoutData(gridData);
	combo.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			notifyObservers();
		}
	});
	Button refresh = new Button(container, SWT.PUSH);
	refresh.setText("Refresh");
	refresh.addListener(SWT.Selection, new Listener() {
		@Override
		public void handleEvent(Event event) {
	        updateOptionsDisplay();
	    }
	});
}
 
Example #16
Source File: CommonMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private CursorLinePainter getCursorLinePainterInstalled(TextViewer viewer)
{
	Listener[] listeners = viewer.getTextWidget().getListeners(3001/* StyledText.LineGetBackground */);
	for (Listener listener : listeners)
	{
		if (listener instanceof TypedListener)
		{
			TypedListener typedListener = (TypedListener) listener;
			if (typedListener.getEventListener() instanceof CursorLinePainter)
			{
				return (CursorLinePainter) typedListener.getEventListener();
			}
		}
	}
	return null;
}
 
Example #17
Source File: SWTTabItem.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void addChild(UIControl control) {
	Control handle = ((SWTControl<? extends Control>) control).getControl();
	
	this.control = control;
	this.item.setControl(handle);
	
	handle.addListener(SWT.Resize, new Listener() {
		public void handleEvent(Event event) {
			onResize();
		}
	});
	handle.getDisplay().asyncExec(new Runnable() {
		public void run() {
			onResize();
		}
	});
}
 
Example #18
Source File: MatchViewerBodyMenu.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public MatchViewerBodyMenu(MatchViewPart view) {
	this.view = view;
	createMenu();
	bodyMenu.addListener(SWT.Show, new Listener() {

		public void handleEvent(Event event) {
			updateActionState();
		}
	});
}
 
Example #19
Source File: ChartSpinner.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void handleEvent( Event event )
{
	if ( event.widget == spinner )
	{
		event.widget = this;
		Listener[] lis = this.getListeners( event.type );
		for ( int i = ( lis.length - 1 ); i >= 0 ; i-- )
		{
			lis[i].handleEvent( event );
		}
	}
}
 
Example #20
Source File: SWTCheckBoxListWidget.java    From atdl4j with MIT License 5 votes vote down vote up
public void addListener(Listener listener)
{
	for ( Button checkBox : multiCheckBox )
	{
		checkBox.addListener( SWT.Selection, listener );
	}
}
 
Example #21
Source File: VControl.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
void handleEvent(Event event) {
	event.data = this;
	filterEvent(event);
	if(listeners != null && listeners.containsKey(event.type)) {
		Listener[] la = listeners.get(event.type).toArray(new Listener[listeners.get(event.type).size()]);
		for(Listener listener : la) {
			listener.handleEvent(event);
		}
	}
}
 
Example #22
Source File: LabelAttributesComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 */
private void init( )
{
	this.setSize( getParent( ).getClientArea( ).width,
			getParent( ).getClientArea( ).height );
	vListeners = new Vector<Listener>( );
}
 
Example #23
Source File: Snippet8.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private Spinner createPageCountSpinner(Composite parent,
		Listener selectionListener) {
	Spinner spinner = new Spinner(parent, SWT.BORDER);
	spinner.setMinimum(1);
	spinner.setMaximum(99);
	spinner.addListener(SWT.Selection, selectionListener);
	return spinner;
}
 
Example #24
Source File: CTreeCell.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
void sendEvent(Event event) {
	if(hasHandler(event.type)) {
		event.data = CTreeCell.this;
		event.item = CTreeCell.this.item; // TODO: necessary?
		Listener[] la = (Listener[]) handlers[event.type].toArray(new Listener[handlers[event.type].size()]);
		for(int i = 0; i < la.length; i++) {
			la[i].handleEvent(event);
		}
	}
}
 
Example #25
Source File: TSTitleAreaDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
protected Control createContents(Composite parent) {
	// create the overall composite
	Composite contents = new Composite(parent, SWT.NONE);
	contents.setLayoutData(new GridData(GridData.FILL_BOTH));
	// initialize the dialog units
	initializeDialogUnits(contents);
	FormLayout layout = new FormLayout();
	contents.setLayout(layout);
	// Now create a work area for the rest of the dialog
	workArea = new Composite(contents, SWT.NONE);
	GridLayout childLayout = new GridLayout();
	childLayout.marginHeight = 0;
	childLayout.marginWidth = 0;
	childLayout.verticalSpacing = 0;
	workArea.setLayout(childLayout);
	Control top = createTitleArea(contents);
	resetWorkAreaAttachments(top);
	workArea.setFont(JFaceResources.getDialogFont());
	// initialize the dialog units
	initializeDialogUnits(workArea);
	// create the dialog area and button bar
	dialogArea = createDialogArea(workArea);
	buttonBar = createButtonBar(workArea);
	
	// computing trim for later
	Point rect = messageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	xTrim = rect.x - 100;
	yTrim = rect.y - 100;
	
	// need to react to new size of title area
	getShell().addListener(SWT.Resize, new Listener() {
		public void handleEvent(Event event) {
			layoutForNewMessage(true);
		}
	});
	return contents;
}
 
Example #26
Source File: MultiValueCombo.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void addListener( int eventType, Listener listener )
{
	if ( addListenerLock == true
			&& ( eventType == SWT.Selection || eventType == SWT.KeyUp || eventType == SWT.KeyDown ) )
	{
		return;
	}

	super.addListener( eventType, listener );
}
 
Example #27
Source File: TreeValueDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates and initializes the tree viewer.
 * 
 * @param parent
 *            the parent composite
 * @return the tree viewer
 * @see #doCreateTreeViewer(Composite, int)
 */
protected TreeViewer createTreeViewer( Composite parent )
{
	TreeViewer treeViewer = super.createTreeViewer( parent );
	Tree tree = treeViewer.getTree( );
	assert ( tree != null );
	for ( int i = 0; i < listeners.size( ); i++ )
	{
		int type = listeners.get( i ).type;
		Listener listener = listeners.get( i ).listener;
		tree.addListener( type, listener );
	}
	return treeViewer;
}
 
Example #28
Source File: SWTRadioButtonListWidget.java    From atdl4j with MIT License 5 votes vote down vote up
public void removeListener(Listener listener)
{
	for ( Button b : buttons )
	{
		b.removeListener( SWT.Selection, listener );
	}
}
 
Example #29
Source File: GetFieldsCapableStepDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
default void getFields( final StepMetaType meta ) {

    final String[] incomingFieldNames = getFieldNames( meta );
    final List<String> newFieldNames = getNewFieldNames( incomingFieldNames );

    if ( newFieldNames != null && newFieldNames.size() > 0 ) {
      // we have new incoming fields
      final int nrNonEmptyFields = getFieldsTable().nrNonEmpty();
      // are any fields already populated in the fields table?
      if ( nrNonEmptyFields > 0 ) {
        final FieldSelectionDialog fieldSelectDialog = new FieldSelectionDialog( this.getShell(), newFieldNames.size() ) {
          @Override protected void ok() {
            super.ok();
            openGetFieldsSampleDataDialog( reloadAllFields );
          }
        };
        fieldSelectDialog.open();
      } else {
        // no fields are populated yet, go straight to "sample data" dialog
        openGetFieldsSampleDataDialog( true );
      }
    } else {
      // we have no new fields
      final BaseDialog errorDlg = new BaseMessageDialog( getShell(),
        BaseMessages.getString( PKG, "System.GetFields.NoNewFields.Title" ),
        BaseMessages.getString( PKG, "System.GetFields.NoNewFields.Message" ) );
      // if there are no incoming fields at all, we leave the OK button handler as-is and simply dispose the dialog;
      // if there are some incoming fields, we overwrite the OK button handler to show the GetFieldsSampleDataDialog
      if ( incomingFieldNames != null && incomingFieldNames.length > 0 ) {
        final Map<String, Listener> buttons = new HashMap<>();
        buttons.put( BaseMessages.getString( PKG, "System.Button.OK" ), event -> {
          errorDlg.dispose();
          openGetFieldsSampleDataDialog( true );
        } );
        errorDlg.setButtons( buttons );
      }
      errorDlg.open();
    }
  }
 
Example #30
Source File: GridViewerColumn.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setEditingSupport(EditingSupport editingSupport)
{
    if (editingSupport instanceof CheckEditingSupport)
    {
        if (checkEditingSupport == null)
        {
            final int colIndex = getColumn().getParent().indexOf(getColumn());
            
            getColumn().getParent().addListener(SWT.Selection, new Listener()
            {                
                public void handleEvent(Event event)
                {                         
                    if (event.detail == SWT.CHECK && event.index == colIndex)
                    {
                        GridItem item = (GridItem)event.item;
                        Object element = item.getData();
                        checkEditingSupport.setValue(element, new Boolean(item.getChecked(colIndex)));
                    }
                }                
            });
        }
        checkEditingSupport = (CheckEditingSupport)editingSupport;
    }
    else
    {
        super.setEditingSupport(editingSupport);
    }        
}