Java Code Examples for org.eclipse.swt.widgets.Button#setData()

The following examples show how to use org.eclipse.swt.widgets.Button#setData() . 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: OperationsComposite.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected Button createRemoveButton(final OperationViewer opViewer) {
    final GridLayout gridLayout = (GridLayout) opViewer.getLayout();
    gridLayout.numColumns++;
    final Button remove = new Button(opViewer, SWT.FLAT);
    if (widgetFactory != null) {
        widgetFactory.adapt(remove, false, false);
    }
    remove.setData("org.eclipse.swtbot.widget.key", SWTBOT_ID_REMOVE_LINE);
    remove.setLayoutData(GridDataFactory.swtDefaults().create());
    remove.setImage(Pics.getImage("delete.png"));
    remove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            removeLine(removes.indexOf(e.getSource()));
        }
    });
    opViewer.layout(true, true);
    return remove;
}
 
Example 2
Source File: AbstractDataSection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected Button createRemoveDataButton(final Composite parent) {
    final Button removeButton = getWidgetFactory().createButton(parent, Messages.removeData, SWT.FLAT);
    removeButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_REMOVE_PROCESS_DATA);
    removeButton.setLayoutData(GridDataFactory.fillDefaults().minSize(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).create());
    removeButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            if (dataTableViewer != null && !((IStructuredSelection) dataTableViewer.getSelection()).isEmpty()) {
                removeData((IStructuredSelection) dataTableViewer.getSelection());
            }
        }

    });
    return removeButton;
}
 
Example 3
Source File: ModulaSearchPage.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private ArrayList<Button> createGroup(Composite parent, int columns, String groupLabel, 
        String[] buttonLabels, int[] buttonData, int defaultSelected) 
{
    ArrayList<Button> buttons = new ArrayList<Button>();
    Group group = new Group(parent, SWT.NONE);
    group.setLayout(new GridLayout(columns, true));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    group.setText(groupLabel);
    for (int i = 0; i < buttonLabels.length; i++) {
        if (buttonLabels[i] != null) {
            Button b = new Button(group, SWT.RADIO);
            b.setData((Integer)buttonData[i]);
            b.setText(buttonLabels[i]);
            b.setSelection(i == defaultSelected);
            buttons.add(b);
        } else {
            new Label(group, SWT.NORMAL); // empty place
        }
    }
    return buttons;
}
 
Example 4
Source File: OptionsConfigurationBlock.java    From typescript.java with MIT License 6 votes vote down vote up
protected Button addCheckBox(Composite parent, String label, Key key, String[] values, int indent) {
	ControlData data = new ControlData(key, values);

	GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	gd.horizontalSpan = 3;
	gd.horizontalIndent = indent;

	Button checkBox = new Button(parent, SWT.CHECK);
	checkBox.setFont(JFaceResources.getDialogFont());
	checkBox.setText(label);
	checkBox.setData(data);
	checkBox.setLayoutData(gd);
	checkBox.addSelectionListener(getSelectionListener());

	makeScrollableCompositeAware(checkBox);

	String currValue = getValue(key);
	checkBox.setSelection(data.getSelection(currValue) == 0);

	fCheckBoxes.add(checkBox);

	return checkBox;
}
 
Example 5
Source File: AboutDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Button createFeatureButton(Composite parent,
          final AboutBundleGroupData info) {
      if (!buttonManager.add(info)) {
	return null;
}

      ImageDescriptor desc = info.getFeatureImage();
      Image featureImage = null;

      Button button = new Button(parent, SWT.FLAT | SWT.PUSH);
      button.setData(info);
      featureImage = desc.createImage();
      images.add(featureImage);
      button.setImage(featureImage);
      button.setToolTipText(info.getProviderName());
      
      button.getAccessible().addAccessibleListener(new AccessibleAdapter(){
      	/* (non-Javadoc)
	 * @see org.eclipse.swt.accessibility.AccessibleAdapter#getName(org.eclipse.swt.accessibility.AccessibleEvent)
	 */
	public void getName(AccessibleEvent e) {
		e.result = info.getProviderName();
	}
      });
      button.addSelectionListener(new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
              AboutBundleGroupData[] groupInfos = buttonManager
                      .getRelatedInfos(info);
              AboutBundleGroupData selection = (AboutBundleGroupData) event.widget
                      .getData();

              AboutFeaturesDialog d = new AboutFeaturesDialog(getShell(),
                      productName, groupInfos, selection);
              d.open();
          }
      });

      return button;
  }
 
Example 6
Source File: JavaSearchPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Button createButton(Composite parent, int style, String text, int data, boolean isSelected) {
	Button button= new Button(parent, style);
	button.setText(text);
	button.setData(new Integer(data));
	button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
	button.setSelection(isSelected);
	return button;
}
 
Example 7
Source File: HadoopLocationWizard.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Create a SWT Checked Button component for the given {@link ConfProp}
 * boolean configuration property.
 * 
 * @param listener
 * @param parent
 * @param prop
 * @return
 */
private Button createConfCheckButton(SelectionListener listener,
    Composite parent, ConfProp prop, String text) {

  Button button = new Button(parent, SWT.CHECK);
  button.setText(text);
  button.setData("hProp", prop);
  button.setSelection(location.getConfProp(prop).equalsIgnoreCase("yes"));
  button.addSelectionListener(listener);

  return button;
}
 
Example 8
Source File: AbstractDataSection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void createAddDataButton(final Composite parent) {
    final Button addDataButton = getWidgetFactory().createButton(parent, Messages.addData, SWT.FLAT);
    addDataButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_ADD_PROCESS_DATA);
    addDataButton.setLayoutData(GridDataFactory.fillDefaults().minSize(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).create());
    addDataButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            addData();
        }

    });
}
 
Example 9
Source File: ExtractMethodUserInputPage.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void createAccessModifierSection(Composite result) {
	GridLayout layout;
	Label label = new Label(result, SWT.NONE);
	label.setText("Access modifier:");
	Composite group = new Composite(result, SWT.NONE);
	group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	layout = new GridLayout();
	layout.numColumns = 3;
	layout.marginWidth = 0;
	group.setLayout(layout);
	String[] labels = new String[] { "public", "protected", "private" };
	JvmVisibility[] data = new JvmVisibility[] { JvmVisibility.PUBLIC, JvmVisibility.PROTECTED,
			JvmVisibility.PRIVATE };
	JvmVisibility visibility = refactoring.getVisibility();
	for (int i = 0; i < labels.length; i++) {
		Button radio = new Button(group, SWT.RADIO);
		radio.setText(labels[i]);
		radio.setData(data[i]);
		if (data[i].equals(visibility))
			radio.setSelection(true);
		radio.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				final JvmVisibility selectedModifier = (JvmVisibility) event.widget.getData();
				visibilityModified(selectedModifier);
				updatePreview();
			}
		});
	}
}
 
Example 10
Source File: ReportConfigurationTab.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Build list of bug categories to be enabled or disabled. Populates
 * chkEnableBugCategoryList and bugCategoryList fields.
 *
 * @param parent
 *            control checkboxes should be added to
 * @param project
 *            the project being configured
 */
private void createBugCategoriesGroup(Composite parent, final IProject project) {
    Group checkBoxGroup = new Group(parent, SWT.SHADOW_ETCHED_OUT);
    checkBoxGroup.setText(getMessage("property.categoriesGroup"));
    checkBoxGroup.setLayout(new GridLayout(1, true));
    checkBoxGroup.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, true));

    List<String> bugCategoryList = new LinkedList<>(DetectorFactoryCollection.instance().getBugCategories());
    chkEnableBugCategoryList = new LinkedList<>();
    ProjectFilterSettings origFilterSettings = propertyPage.getOriginalUserPreferences().getFilterSettings();
    for (String category : bugCategoryList) {
        Button checkBox = new Button(checkBoxGroup, SWT.CHECK);
        checkBox.setText(I18N.instance().getBugCategoryDescription(category));
        checkBox.setSelection(origFilterSettings.containsCategory(category));
        GridData layoutData = new GridData();
        layoutData.horizontalIndent = 10;
        checkBox.setLayoutData(layoutData);

        // Every time a checkbox is clicked, rebuild the detector factory
        // table
        // to show only relevant entries
        checkBox.addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event e) {
                syncSelectedCategories();
            }
        });
        checkBox.setData(category);
        chkEnableBugCategoryList.add(checkBox);
    }
}
 
Example 11
Source File: TSWizardDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the Cancel button for this wizard dialog. Creates a standard (<code>SWT.PUSH</code>)
 * button and registers for its selection events. Note that the number of
 * columns in the button bar composite is incremented. The Cancel button is
 * created specially to give it a removeable listener.
 * 
 * @param parent
 *            the parent button bar
 * @return the new Cancel button
 */
private Button createCancelButton(Composite parent) {
	// increment the number of columns in the button bar
	((GridLayout) parent.getLayout()).numColumns++;
	Button button = new Button(parent, SWT.PUSH);
	button.setText(IDialogConstants.CANCEL_LABEL);
	setButtonLayoutData(button);
	button.setFont(parent.getFont());
	button.setData(new Integer(IDialogConstants.CANCEL_ID));
	button.addSelectionListener(cancelListener);
	return button;
}
 
Example 12
Source File: HadoopLocationWizard.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Create a SWT Checked Button component for the given {@link ConfProp}
 * boolean configuration property.
 * 
 * @param listener
 * @param parent
 * @param prop
 * @return
 */
private Button createConfCheckButton(SelectionListener listener,
    Composite parent, ConfProp prop, String text) {

  Button button = new Button(parent, SWT.CHECK);
  button.setText(text);
  button.setData("hProp", prop);
  button.setSelection(location.getConfProp(prop).equalsIgnoreCase("yes"));
  button.addSelectionListener(listener);

  return button;
}
 
Example 13
Source File: OptionsConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Button addCheckboxWithData(Composite parent, String label, ControlData data, GridData gd) {
	Button checkBox = new Button(parent, SWT.CHECK);
	checkBox.setFont(JFaceResources.getDialogFont());
	checkBox.setText(label);
	checkBox.setData(data);
	checkBox.setLayoutData(gd);
	checkBox.addSelectionListener(getSelectionListener());
	makeScrollableCompositeAware(checkBox);
	updateCheckBox(checkBox);
	checkBoxes.add(checkBox);
	return checkBox;
}
 
Example 14
Source File: OutputParametersMappingSection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void addOutputMappingControl(final Composite parent) {
    final Composite composite = getWidgetFactory().createComposite(parent);
    composite.setLayout(GridLayoutFactory.fillDefaults().create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    outputMappingControl = new MagicComposite(composite, SWT.NONE);
    outputMappingControl.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    getWidgetFactory().adapt(outputMappingControl);
    outputMappingControl.setLayout(GridLayoutFactory.fillDefaults().numColumns(4).margins(0, 0).create());

    final Label targetParameterLabel = getWidgetFactory().createLabel(outputMappingControl,
            Messages.dataFromCalledProcess);
    targetParameterLabel.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).indent(15, 0).create());
    final Control sourceParameterLabel = getWidgetFactory().createLabel(outputMappingControl,
            Messages.dataInRootProcess);
    sourceParameterLabel.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).create());

    final IObservableValue inputMappibngsObservable = CustomEMFEditObservables.observeDetailValue(Realm.getDefault(),
            ViewersObservables.observeSingleSelection(selectionProvider),
            ProcessPackage.Literals.CALL_ACTIVITY__OUTPUT_MAPPINGS);
    dbc.bindValue(SWTObservables.observeVisible(sourceParameterLabel), inputMappibngsObservable,
            neverUpdateValueStrategy().create(), updateValueStrategy().withConverter(hideIfEmpty()).create());
    dbc.bindValue(SWTObservables.observeVisible(targetParameterLabel), inputMappibngsObservable,
            neverUpdateValueStrategy().create(), updateValueStrategy().withConverter(hideIfEmpty()).create());

    final Button addLineButton = getWidgetFactory().createButton(composite, Messages.Add, SWT.FLAT);
    addLineButton.setLayoutData(
            GridDataFactory.swtDefaults().hint(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).indent(15, 0).create());
    addLineButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
            SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_ADD_OUTPUT);
    addLineButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            createOutputMapping(null, null);
            refreshScrolledComposite(parent);
        }
    });

}
 
Example 15
Source File: PWRadio.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
 */
@Override
public Control build(final Composite parent) {
	buildLabel(parent, GridData.BEGINNING);

	final Composite composite = new Composite(parent, SWT.NONE);
	final GridLayout gridLayout = new GridLayout();
	gridLayout.marginHeight = gridLayout.marginWidth = 0;
	composite.setLayout(gridLayout);

	for (final Object datum : data) {
		final Button button = new Button(composite, SWT.RADIO);
		addControl(button);
		button.setText(datum.toString());
		button.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
		button.setSelection(datum.equals(PreferenceWindow.getInstance().getValueFor(getPropertyKey())));
		button.setData(datum);
		button.addListener(SWT.Selection, event -> {
			if (button.getSelection()) {
				PreferenceWindow.getInstance().setValue(getPropertyKey(), button.getData());
			}
		});

		buttons.add(button);
	}
	return composite;
}
 
Example 16
Source File: MultiChoice.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create the popup that contains all checkboxes
 */
private void createPopup() {
	this.popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
	this.popup.setLayout(new FillLayout());

	final int[] popupEvents = { SWT.Close, SWT.Deactivate, SWT.Dispose };
	for (final int popupEvent : popupEvents) {
		this.popup.addListener(popupEvent, this.listener);
	}

	if (this.elements == null) {
		return;
	}

	this.scrolledComposite = new ScrolledComposite(this.popup, SWT.BORDER | SWT.V_SCROLL);
	final Composite content = new Composite(this.scrolledComposite, SWT.NONE);
	content.setLayout(new GridLayout(this.numberOfColumns, true));

	this.checkboxes = new ArrayList<>(this.elements.size());
	for (final T o : this.elements) {
		final Button checkBoxButton = new Button(content, SWT.CHECK);

		if (this.font != null) {
			checkBoxButton.setFont(this.font);
		}
		if (this.foreground != null) {
			checkBoxButton.setForeground(this.foreground);
		}
		if (this.background != null) {
			checkBoxButton.setBackground(this.background);
		}
		checkBoxButton.setEnabled(text.getEditable());

		checkBoxButton.setData(o);
		checkBoxButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
		checkBoxButton.setText(this.labelProvider.getText(o));
		checkBoxButton.addListener(SWT.Selection, e -> {
			if (checkBoxButton.getSelection()) {
				MultiChoice.this.selection.add(o);
			} else {
				MultiChoice.this.selection.remove(o);
			}
			MultiChoice.this.lastModified = o;
			setLabel();
		});

		if (this.selectionListener != null) {
			checkBoxButton.addSelectionListener(this.selectionListener);
		}

		checkBoxButton.setSelection(this.selection.contains(o));
		this.checkboxes.add(checkBoxButton);
	}

	this.scrolledComposite.setContent(content);
	this.scrolledComposite.setExpandHorizontal(false);
	this.scrolledComposite.setExpandVertical(true);
	content.pack();
	this.preferredHeightOfPopup = content.getSize().y;
}
 
Example 17
Source File: RouteResourceController.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow,
        final int nbInRow, final int top, final Control lastControl) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    FormData data;

    final DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER | SWT.READ_ONLY,
            new SelectAllTextControlCreator());
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
                FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    Control cLayout = dField.getLayoutControl();

    labelText = (Text) dField.getControl();

    labelText.setData(PARAMETER_NAME, param.getName());

    cLayout.setBackground(subComposite.getBackground());
    labelText.setEditable(false);
    if (elem instanceof Node) {
        labelText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }

    addDragAndDropTarget(labelText);

    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment(((numInRow - 1) * MAX_PERCENT) / (nbInRow + 1), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }

    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }

    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }

    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.right = new FormAttachment((numInRow * MAX_PERCENT) / (nbInRow + 1), 0);
    data.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);

    Button btn;
    Point btnSize;

    btn = getWidgetFactory().createButton(subComposite, "", SWT.PUSH); //$NON-NLS-1$
    btnSize = btn.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    btn.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));

    btn.addSelectionListener(listenerSelection);
    btn.setData(PARAMETER_NAME, param.getName());
    btn.setEnabled(!param.isReadOnly());
    data = new FormData();
    data.left = new FormAttachment(cLayout, 0);
    data.right = new FormAttachment(cLayout, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    data.top = new FormAttachment(0, top);
    data.height = STANDARD_HEIGHT - 2;
    btn.setLayoutData(data);

    hashCurControls.put(param.getName(), labelText);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Control lastControlUsed = btn;
    lastControlUsed = addVersionCombo(subComposite,
            param.getChildParameters().get(EParameterName.ROUTE_RESOURCE_TYPE_VERSION.getName()), lastControlUsed,
            numInRow + 1, nbInRow, top);
    dynamicProperty.setCurRowSize(Math.max(initialSize.y, btnSize.y) + ITabbedPropertyConstants.VSPACE);
    return btn;
}
 
Example 18
Source File: ExtractConstantWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void addAccessModifierGroup(Composite result, RowLayouter layouter) {
	fAccessModifier= getExtractConstantRefactoring().getVisibility();
	if (getExtractConstantRefactoring().getTargetIsInterface())
		return;

	Label label= new Label(result, SWT.NONE);
	label.setText(RefactoringMessages.ExtractConstantInputPage_access_modifiers);

	Composite group= new Composite(result, SWT.NONE);
	group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	GridLayout layout= new GridLayout();
	layout.numColumns= 4; layout.marginWidth= 0;
	group.setLayout(layout);

	String[] labels= new String[] {
		RefactoringMessages.ExtractMethodInputPage_public,
		RefactoringMessages.ExtractMethodInputPage_protected,
		RefactoringMessages.ExtractMethodInputPage_default,
		RefactoringMessages.ExtractMethodInputPage_private
	};
	String[] data= new String[] { JdtFlags.VISIBILITY_STRING_PUBLIC,
								  JdtFlags.VISIBILITY_STRING_PROTECTED,
								  JdtFlags.VISIBILITY_STRING_PACKAGE,
								  JdtFlags.VISIBILITY_STRING_PRIVATE }; //

	updateContentAssistImage();
	for (int i= 0; i < labels.length; i++) {
		Button radio= new Button(group, SWT.RADIO);
		radio.setText(labels[i]);
		radio.setData(data[i]);
		if (data[i] == fAccessModifier)
			radio.setSelection(true);
		radio.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				setAccessModifier((String)event.widget.getData());
			}
		});
	}
	layouter.perform(label, group, 1);
}
 
Example 19
Source File: ThemePreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void createButton(final Table table, final TableItem tableItem, final int index, final RGBa color)
{
	TableEditor editor = new TableEditor(table);
	Button button = new Button(table, SWT.PUSH | SWT.FLAT);
	Image image = createColorImage(table, color);
	button.setImage(image);
	button.pack();
	editor.minimumWidth = button.getSize().x - 4;
	editor.horizontalAlignment = SWT.CENTER;
	editor.setEditor(button, tableItem, index);
	fTableEditors.add(editor);
	button.setData("color", color); //$NON-NLS-1$

	button.addSelectionListener(new SelectionAdapter()
	{
		@Override
		public void widgetSelected(SelectionEvent e)
		{
			ColorDialog colorDialog = new ColorDialog(table.getShell());
			Button self = ((Button) e.widget);
			RGBa theColor = (RGBa) self.getData("color"); //$NON-NLS-1$
			if (theColor == null)
			{
				theColor = color;
			}
			colorDialog.setRGB(theColor.toRGB());
			RGB newRGB = colorDialog.open();
			if (newRGB == null)
			{
				return;
			}
			ThemeRule token = (ThemeRule) tableItem.getData();
			RGBa newColor = new RGBa(newRGB);
			if (index == 1)
			{
				getTheme().updateRule(table.indexOf(tableItem), token.updateFG(newColor));
			}
			else
			{
				getTheme().updateRule(table.indexOf(tableItem), token.updateBG(newColor));
			}
			// Update the image for this button!
			self.setImage(createColorImage(table, newColor));
			self.setData("color", newColor); //$NON-NLS-1$
			tableViewer.refresh();
		}
	});

	// Allow dragging the button out of it's location to remove the fg/bg for the rule!
	Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
	final DragSource source = new DragSource(button, DND.DROP_MOVE);
	source.setTransfer(types);

	source.addDragListener(new DragSourceAdapter()
	{
		public void dragSetData(DragSourceEvent event)
		{
			event.data = "button:" + table.indexOf(tableItem) + ":" + index; //$NON-NLS-1$ //$NON-NLS-2$
		}
	});
}
 
Example 20
Source File: CMakePropertyTab.java    From cmake4eclipse with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Switches the specified button behavior from tri-state mode to toggle mode.
 *
 * @param button
 *          the button to modify
 * @param buttonSelected
 *          the selection of the button
 */
private static void enterToggleMode(Button button, boolean buttonSelected) {
  button.setData(null); // mark toggle mode
  button.setSelection(buttonSelected);
  button.setGrayed(false);
}