@NotNull public static Button createLabelCheckbox( @NotNull Composite parent, @NotNull String label, @Nullable String tooltip, boolean checked, int style) { Label labelControl = createControlLabel(parent, label); // labelControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Button button = new Button(parent, SWT.CHECK | style); if (checked) { button.setSelection(true); } labelControl.addMouseListener( new MouseAdapter() { @Override public void mouseUp(MouseEvent e) { if (!button.isDisposed() && button.isVisible() && button.isEnabled()) { button.setSelection(!button.getSelection()); button.notifyListeners(SWT.Selection, new Event()); } } }); if (tooltip != null) { labelControl.setToolTipText(tooltip); button.setToolTipText(tooltip); } return button; }
private void createOptionalDependenciesButton(Composite container) { if (isEditable()) { fIncludeOptionalButton = new Button(container, SWT.CHECK); fIncludeOptionalButton.setText(PDEUIMessages.PluginSection_includeOptional); // initialize value IEditorInput input = getPage().getEditorInput(); if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) input).getFile(); try { fIncludeOptionalButton.setSelection( "true".equals(file.getPersistentProperty(OPTIONAL_PROPERTY))); // $NON-NLS-1$ } catch (CoreException e) { } } // create listener to save value when the checkbox is changed fIncludeOptionalButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IEditorInput input = getPage().getEditorInput(); if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) input).getFile(); try { file.setPersistentProperty( OPTIONAL_PROPERTY, fIncludeOptionalButton.getSelection() ? "true" : null); // $NON-NLS-1$ } catch (CoreException e1) { } } } }); } }
public static Button createCheckbox(Composite parent, String label, boolean checked) { final Button button = new Button(parent, SWT.CHECK); button.setText(label); if (checked) { button.setSelection(true); } return button; }