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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #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: GraphvizConfigurationDialog.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Control createMessageArea(Composite composite) {
	// prevent creation of messageLabel by super implementation
	String linkText = message;
	message = null;
	super.createMessageArea(composite);
	message = linkText;

	Link messageLink = new Link(composite, SWT.WRAP);
	messageLink.setText(message);
	GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
			.grab(true, false).applyTo(messageLink);
	messageLink.addListener(SWT.Selection, new Listener() {
		@Override
		public void handleEvent(Event event) {
			Shell shell = PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow().getShell();
			PreferenceDialog pref = PreferencesUtil
					.createPreferenceDialogOn(shell,
							"org.eclipse.gef.dot.internal.ui.GraphvizPreferencePage", //$NON-NLS-1$
							null, null);
			if (pref != null) {
				close();
				pref.open();
			}
		}
	});
	return composite;
}
 
Example #20
Source File: TmfRawEventViewer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Remove selection listener
 * @param listener A listener to remove
 */
public void removeSelectionListener(Listener listener) {
    checkWidget();
    if (listener == null) {
        SWT.error (SWT.ERROR_NULL_ARGUMENT);
    }
    removeListener(SWT.Selection, listener);
}
 
Example #21
Source File: ConnectorSection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Button createUpdateConnectorButton(final Composite parent) {
    final Button updateButton = getWidgetFactory().createButton(parent,
            Messages.update, SWT.FLAT);
    updateButton.setLayoutData(GridDataFactory.fillDefaults()
            .minSize(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).create());
    updateButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            updateConnectorAction();
        }
    });
    return updateButton;
}
 
Example #22
Source File: MissingRequirementsDialog.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	Composite composite = (Composite) super.createDialogArea(parent);
	Link messageLnk = new Link(composite,SWT.NONE);
	messageLnk.setText(this.message);
	messageLnk.addListener(SWT.Selection, new Listener() {
		
		@Override
		public void handleEvent(Event event) {
			OpenCheatSheetAction ch = new OpenCheatSheetAction("org.eclipse.thym.ui.requirements.cordova");
			ch.run();
		}
	});
	return composite;
}
 
Example #23
Source File: SimpleDemo.java    From lwjgl3-swt with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    // Create the Vulkan instance
    VkInstance instance = createInstance();

    // Create SWT Display, Shell and VKCanvas
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE);
    shell.setLayout(new FillLayout());
    shell.addListener(SWT.Traverse, new Listener() {
        public void handleEvent(Event event) {
            switch (event.detail) {
            case SWT.TRAVERSE_ESCAPE:
                shell.close();
                event.detail = SWT.TRAVERSE_NONE;
                event.doit = false;
                break;
            }
        }
    });
    VKData data = new VKData();
    data.instance = instance; // <- set Vulkan instance
    final VKCanvas canvas = new VKCanvas(shell, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE, data);
    shell.setSize(800, 600);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    canvas.dispose();
    display.dispose();
}
 
Example #24
Source File: GanttLineAttributesComposite.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 #25
Source File: DateTimeDataElementComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public DateTimeDataElementComposite( Composite parent, int style,
		DateTimeDataElement data, boolean isNullAllowed )
{
	super( parent, SWT.NONE );
	this.isNullAllowed = isNullAllowed;

	placeComponents( style );

	vListeners = new Vector<Listener>( );

	setDataElement( data );
}
 
Example #26
Source File: Breadcrumb.java    From SWET with MIT License 5 votes vote down vote up
private void addMouseUpListener() {
	addListener(SWT.MouseUp, new Listener() {
		@Override
		public void handleEvent(final Event event) {
			for (final BreadcrumbItem item : Breadcrumb.this.items) {
				if (item.getBounds().contains(event.x, event.y)) {
					if (item.getData(IS_BUTTON_PRESSED) == null) {
						// The button was not pressed
						return;
					}
					item.setData(IS_BUTTON_PRESSED, null);

					if ((item.getStyle() & SWT.PUSH) != 0) {
						item.setSelection(false);
					}

					if ((item.getStyle() & (SWT.TOGGLE | SWT.PUSH)) != 0) {
						item.fireSelectionEvent();
						redraw();
						update();
					}
					return;
				}
			}
		}
	});
}
 
Example #27
Source File: LocalMapReduceLaunchTabGroup.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
private void createRow(final Composite parent, Composite panel,
    final Text text) {
  text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  Button button = new Button(panel, SWT.BORDER);
  button.setText("Browse...");
  button.addListener(SWT.Selection, new Listener() {
    public void handleEvent(Event arg0) {
      try {
        AST ast = AST.newAST(3);

        SelectionDialog dialog = JavaUI.createTypeDialog(parent.getShell(),
            new ProgressMonitorDialog(parent.getShell()), SearchEngine
                .createWorkspaceScope(),
            IJavaElementSearchConstants.CONSIDER_CLASSES, false);
        dialog.setMessage("Select Mapper type (implementing )");
        dialog.setBlockOnOpen(true);
        dialog.setTitle("Select Mapper Type");
        dialog.open();

        if ((dialog.getReturnCode() == Window.OK)
            && (dialog.getResult().length > 0)) {
          IType type = (IType) dialog.getResult()[0];
          text.setText(type.getFullyQualifiedName());
          setDirty(true);
        }
      } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  });
}
 
Example #28
Source File: GridViewerColumn.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setEditingSupport(EditingSupport editingSupport)
{
	currentEditingSupport = editingSupport;
	if (!getColumn().isVisible()) {
		return;
	}

    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);
    }
}
 
Example #29
Source File: WidgetUtils.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * creates a ComboVar populated with fields from the previous step.
 * @param parentComposite - the composite in which the widget will be placed
 * @param props - PropsUI props for L&F
 * @param stepMeta - stepMeta of the current step
 * @param formData - FormData to use for placement
 */
public static ComboVar createFieldDropDown(
  Composite parentComposite, PropsUI props, BaseStepMeta stepMeta, FormData formData ) {
  TransMeta transMeta = stepMeta.getParentStepMeta().getParentTransMeta();
  ComboVar fieldDropDownCombo = new ComboVar( transMeta, parentComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER );
  props.setLook( fieldDropDownCombo );
  fieldDropDownCombo.addModifyListener( e -> stepMeta.setChanged() );

  fieldDropDownCombo.setLayoutData( formData );
  Listener focusListener = e -> {
    String current = fieldDropDownCombo.getText();
    fieldDropDownCombo.getCComboWidget().removeAll();
    fieldDropDownCombo.setText( current );

    try {
      RowMetaInterface rmi = transMeta.getPrevStepFields( stepMeta.getParentStepMeta().getName() );
      List ls = rmi.getValueMetaList();
      for ( Object l : ls ) {
        ValueMetaBase vmb = (ValueMetaBase) l;
        fieldDropDownCombo.add( vmb.getName() );
      }
    } catch ( KettleStepException ex ) {
      // can be ignored, since previous step may not be set yet.
      stepMeta.logDebug( ex.getMessage(), ex );
    }
  };
  fieldDropDownCombo.getCComboWidget().addListener( SWT.FocusIn, focusListener );
  return fieldDropDownCombo;
}
 
Example #30
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;
}