mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Bug #182450 : TriButton update
This commit is contained in:
parent
51d62cd4f5
commit
82ab376180
2 changed files with 75 additions and 21 deletions
|
@ -325,34 +325,25 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab {
|
|||
setupControl(b, span, mode);
|
||||
b.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
triButtonPressed(event);
|
||||
checkPressed(event);
|
||||
}});
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selection handler for checkbox created by method "setupCheck()"
|
||||
* Descendants should override this method if they use "setupCheck".
|
||||
* Selection handler for checkbox created
|
||||
* by methods "setupCheck()" or "setupTri()"
|
||||
* Descendants should override this method
|
||||
* if they use "setupCheck".
|
||||
* Usually the method body will look like:
|
||||
* {
|
||||
* Button b = (Button)e.widget;
|
||||
* Control b = (Control)e.widget;
|
||||
* if (b.equals(myFirstCheckbox) { ... }
|
||||
* else if (b.equals(mySecondCheckbox) { ... }
|
||||
* ... }
|
||||
*/
|
||||
protected void checkPressed(SelectionEvent e) {}
|
||||
|
||||
/**
|
||||
* Substitutes combo or button
|
||||
* with its parent (triButton)
|
||||
* @param e
|
||||
*/
|
||||
protected void triButtonPressed(SelectionEvent e) {
|
||||
Control w = (Control)e.widget;
|
||||
e.widget = w.getParent();
|
||||
checkPressed(e);
|
||||
}
|
||||
|
||||
protected void setupControl(Control c, int span, int mode) {
|
||||
// although we use GridLayout usually,
|
||||
// exceptions can occur: do nothing.
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Intel Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.newui;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
|
@ -8,9 +25,10 @@ import org.eclipse.swt.layout.GridLayout;
|
|||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
public class TriButton extends Composite {
|
||||
public class TriButton extends Composite implements SelectionListener {
|
||||
private static final String[] ITEMS = {"No", "Yes", "?"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
public static final int NO = 0;
|
||||
|
@ -21,7 +39,12 @@ public class TriButton extends Composite {
|
|||
private Button button = null;
|
||||
private Combo combo = null;
|
||||
private Label label = null;
|
||||
|
||||
private List listeners = new LinkedList();
|
||||
|
||||
public TriButton(Composite parent, int style) {
|
||||
this(parent, style, true);
|
||||
}
|
||||
|
||||
public TriButton(Composite parent, int style, boolean _triMode) {
|
||||
super(parent, style);
|
||||
triMode = _triMode;
|
||||
|
@ -30,12 +53,20 @@ public class TriButton extends Composite {
|
|||
combo = new Combo(this, style | SWT.READ_ONLY | SWT.DROP_DOWN);
|
||||
combo.setLayoutData(new GridData(GridData.BEGINNING));
|
||||
combo.setItems(ITEMS);
|
||||
combo.addSelectionListener(this);
|
||||
label = new Label(this, SWT.NONE);
|
||||
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
label.addMouseListener(new MouseListener() {
|
||||
public void mouseDoubleClick(MouseEvent e) {}
|
||||
public void mouseDown(MouseEvent e) {}
|
||||
public void mouseUp(MouseEvent e) {
|
||||
processMouseUp(e);
|
||||
}});
|
||||
} else {
|
||||
setLayout(new GridLayout());
|
||||
button = new Button(this, style | SWT.CHECK);
|
||||
button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
button.addSelectionListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,12 +125,44 @@ public class TriButton extends Composite {
|
|||
}
|
||||
|
||||
public void addSelectionListener (SelectionListener listener) {
|
||||
if (triMode) combo.addSelectionListener(listener);
|
||||
else button.addSelectionListener(listener);
|
||||
listeners.add(listener);
|
||||
}
|
||||
public void removeSelectionListener (SelectionListener listener) {
|
||||
if (triMode) combo.removeSelectionListener(listener);
|
||||
else button.removeSelectionListener(listener);
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
e.widget = this;
|
||||
Iterator it = listeners.iterator();
|
||||
while (it.hasNext())
|
||||
((SelectionListener)it.next()).widgetDefaultSelected(e);
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
e.widget = this;
|
||||
Iterator it = listeners.iterator();
|
||||
while (it.hasNext())
|
||||
((SelectionListener)it.next()).widgetSelected(e);
|
||||
}
|
||||
|
||||
private void processMouseUp(MouseEvent me) {
|
||||
int x = combo.getSelectionIndex() + 1;
|
||||
if (x < 0 || x > 2) x = 0;
|
||||
combo.select(x);
|
||||
|
||||
Event e = new Event();
|
||||
e.button = me.button;
|
||||
e.count = me.count;
|
||||
e.data = me.data;
|
||||
e.display = me.display;
|
||||
e.stateMask = me.stateMask;
|
||||
e.time = me.time;
|
||||
e.x = me.x;
|
||||
e.y = me.y;
|
||||
e.type = SWT.Selection;
|
||||
e.doit = true;
|
||||
e.item = this;
|
||||
e.widget = this;
|
||||
SelectionEvent se = new SelectionEvent(e);
|
||||
widgetSelected(se);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue