1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Added the 'org.eclipse.cdt.debug.internal.ui.dialogfields' package.

This commit is contained in:
Mikhail Khodjaiants 2002-12-20 22:26:06 +00:00
parent c2ed9818ca
commit 776735b2af
15 changed files with 2586 additions and 0 deletions

View file

@ -1,3 +1,6 @@
2002-12-19 Mikhail Khodjaiants
Added the 'org.eclipse.cdt.debug.internal.ui.dialogfields' package.
2002-12-19 Mikhail Khodjaiants 2002-12-19 Mikhail Khodjaiants
Added new utility class - SWTUtil Added new utility class - SWTUtil
* SWTUtil.java * SWTUtil.java

View file

@ -0,0 +1,209 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
/**
* A list with checkboxes and a button bar. Typical buttons are 'Check All' and 'Uncheck All'.
* List model is independend of widget creation.
* DialogFields controls are: Label, List and Composite containing buttons.
*/
public class CheckedListDialogField extends ListDialogField {
private int fCheckAllButtonIndex;
private int fUncheckAllButtonIndex;
private List fCheckElements;
public CheckedListDialogField(IListAdapter adapter, String[] customButtonLabels, ILabelProvider lprovider) {
super(adapter, customButtonLabels, lprovider);
fCheckElements= new ArrayList();
fCheckAllButtonIndex= -1;
fUncheckAllButtonIndex= -1;
}
/**
* Sets the index of the 'check' button in the button label array passed in the constructor.
* The behaviour of the button marked as the check button will then be handled internally.
* (enable state, button invocation behaviour)
*/
public void setCheckAllButtonIndex(int checkButtonIndex) {
Assert.isTrue(checkButtonIndex < fButtonLabels.length);
fCheckAllButtonIndex= checkButtonIndex;
}
/**
* Sets the index of the 'uncheck' button in the button label array passed in the constructor.
* The behaviour of the button marked as the uncheck button will then be handled internally.
* (enable state, button invocation behaviour)
*/
public void setUncheckAllButtonIndex(int uncheckButtonIndex) {
Assert.isTrue(uncheckButtonIndex < fButtonLabels.length);
fUncheckAllButtonIndex= uncheckButtonIndex;
}
/*
* @see ListDialogField#createTableViewer
*/
protected TableViewer createTableViewer(Composite parent) {
Table table= new Table(parent, SWT.CHECK + getListStyle());
CheckboxTableViewer tableViewer= new CheckboxTableViewer(table);
tableViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent e) {
doCheckStateChanged(e);
}
});
return tableViewer;
}
/*
* @see ListDialogField#getListControl
*/
public Control getListControl(Composite parent) {
Control control= super.getListControl(parent);
if (parent != null) {
((CheckboxTableViewer)fTable).setCheckedElements(fCheckElements.toArray());
}
return control;
}
/*
* @see DialogField#dialogFieldChanged
* Hooks in to get element changes to update check model.
*/
public void dialogFieldChanged() {
for (int i= fCheckElements.size() -1; i >= 0; i--) {
if (!fElements.contains(fCheckElements.get(i))) {
fCheckElements.remove(i);
}
}
super.dialogFieldChanged();
}
private void checkStateChanged() {
//call super and do not update check model
super.dialogFieldChanged();
}
/**
* Gets the checked elements.
*/
public List getCheckedElements() {
return new ArrayList(fCheckElements);
}
/**
* Returns true if the element is checked.
*/
public boolean isChecked(Object obj) {
return fCheckElements.contains(obj);
}
/**
* Sets the checked elements.
*/
public void setCheckedElements(List list) {
fCheckElements= new ArrayList(list);
if (fTable != null) {
((CheckboxTableViewer)fTable).setCheckedElements(list.toArray());
}
checkStateChanged();
}
/**
* Sets the checked state of an element.
*/
public void setChecked(Object object, boolean state) {
setCheckedWithoutUpdate(object, state);
checkStateChanged();
}
/**
* Sets the checked state of an element. no dialog changed listener informed
*/
public void setCheckedWithoutUpdate(Object object, boolean state) {
if (!fCheckElements.contains(object)) {
fCheckElements.add(object);
}
if (fTable != null) {
((CheckboxTableViewer)fTable).setChecked(object, state);
}
}
/**
* Sets the check state of all elements
*/
public void checkAll(boolean state) {
if (state) {
fCheckElements= getElements();
} else {
fCheckElements.clear();
}
if (fTable != null) {
((CheckboxTableViewer)fTable).setAllChecked(state);
}
checkStateChanged();
}
private void doCheckStateChanged(CheckStateChangedEvent e) {
if (e.getChecked()) {
fCheckElements.add(e.getElement());
} else {
fCheckElements.remove(e.getElement());
}
checkStateChanged();
}
// ------ enable / disable management
/*
* @see ListDialogField#getManagedButtonState
*/
protected boolean getManagedButtonState(ISelection sel, int index) {
if (index == fCheckAllButtonIndex) {
return !fElements.isEmpty();
} else if (index == fUncheckAllButtonIndex) {
return !fElements.isEmpty();
}
return super.getManagedButtonState(sel, index);
}
/*
* @see ListDialogField#extraButtonPressed
*/
protected boolean managedButtonPressed(int index) {
if (index == fCheckAllButtonIndex) {
checkAll(true);
} else if (index == fUncheckAllButtonIndex) {
checkAll(false);
} else {
return super.managedButtonPressed(index);
}
return true;
}
}

View file

@ -0,0 +1,219 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
/**
* Dialog field containing a label and a combo control.
*/
public class ComboDialogField extends DialogField {
private String fText;
private int fSelectionIndex;
private String[] fItems;
private Combo fComboControl;
private ModifyListener fModifyListener;
private int fFlags;
public ComboDialogField(int flags) {
super();
fText= ""; //$NON-NLS-1$
fItems= new String[0];
fFlags= flags;
fSelectionIndex= -1;
}
// ------- layout helpers
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
assertEnoughColumns(nColumns);
Label label= getLabelControl(parent);
label.setLayoutData(gridDataForLabel(1));
Combo combo= getComboControl(parent);
combo.setLayoutData(gridDataForCombo(nColumns - 1));
return new Control[] { label, combo };
}
/*
* @see DialogField#getNumberOfControls
*/
public int getNumberOfControls() {
return 2;
}
protected static GridData gridDataForCombo(int span) {
GridData gd= new GridData();
gd.horizontalAlignment= gd.FILL;
gd.grabExcessHorizontalSpace= false;
gd.horizontalSpan= span;
return gd;
}
// ------- focus methods
/*
* @see DialogField#setFocus
*/
public boolean setFocus() {
if (isOkToUse(fComboControl)) {
fComboControl.setFocus();
}
return true;
}
// ------- ui creation
/**
* Creates or returns the created combo control.
* @param parent The parent composite or <code>null</code> when the widget has
* already been created.
*/
public Combo getComboControl(Composite parent) {
if (fComboControl == null) {
assertCompositeNotNull(parent);
fModifyListener= new ModifyListener() {
public void modifyText(ModifyEvent e) {
doModifyText(e);
}
};
SelectionListener selectionListener= new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
doSelectionChanged(e);
}
public void widgetDefaultSelected(SelectionEvent e) { };
};
fComboControl= new Combo(parent, fFlags);
// moved up due to 1GEUNW2
fComboControl.setItems(fItems);
if (fSelectionIndex != -1) {
fComboControl.select(fSelectionIndex);
} else {
fComboControl.setText(fText);
}
fComboControl.setFont(parent.getFont());
fComboControl.addModifyListener(fModifyListener);
fComboControl.addSelectionListener(selectionListener);
fComboControl.setEnabled(isEnabled());
}
return fComboControl;
}
private void doModifyText(ModifyEvent e) {
if (isOkToUse(fComboControl)) {
fText= fComboControl.getText();
fSelectionIndex= fComboControl.getSelectionIndex();
}
dialogFieldChanged();
}
private void doSelectionChanged(SelectionEvent e) {
if (isOkToUse(fComboControl)) {
fItems= fComboControl.getItems();
fText= fComboControl.getText();
fSelectionIndex= fComboControl.getSelectionIndex();
}
dialogFieldChanged();
}
// ------ enable / disable management
/*
* @see DialogField#updateEnableState
*/
protected void updateEnableState() {
super.updateEnableState();
if (isOkToUse(fComboControl)) {
fComboControl.setEnabled(isEnabled());
}
}
// ------ text access
/**
* Gets the combo items.
*/
public String[] getItems() {
return fItems;
}
/**
* Sets the combo items. Triggers a dialog-changed event.
*/
public void setItems(String[] items) {
fItems= items;
if (isOkToUse(fComboControl)) {
fComboControl.setItems(items);
}
dialogFieldChanged();
}
/**
* Gets the text.
*/
public String getText() {
return fText;
}
/**
* Sets the text. Triggers a dialog-changed event.
*/
public void setText(String text) {
fText= text;
if (isOkToUse(fComboControl)) {
fComboControl.setText(text);
} else {
dialogFieldChanged();
}
}
/**
* Selects an item.
*/
public void selectItem(int index) {
if (isOkToUse(fComboControl)) {
fComboControl.select(index);
} else {
if (index >= 0 && index < fItems.length) {
fText= fItems[index];
fSelectionIndex= index;
}
}
dialogFieldChanged();
}
public int getSelectionIndex() {
return fSelectionIndex;
}
/**
* Sets the text without triggering a dialog-changed event.
*/
public void setTextWithoutUpdate(String text) {
fText= text;
if (isOkToUse(fComboControl)) {
fComboControl.removeModifyListener(fModifyListener);
fComboControl.setText(text);
fComboControl.addModifyListener(fModifyListener);
}
}
}

View file

@ -0,0 +1,222 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.jface.util.Assert;
/**
* Base class of all dialog fields.
* Dialog fields manage controls together with the model, independed
* from the creation time of the widgets.
* - support for automated layouting.
* - enable / disable, set focus a concept of the base class.
*
* DialogField have a label.
*/
public class DialogField {
private Label fLabel;
protected String fLabelText;
private IDialogFieldListener fDialogFieldListener;
private boolean fEnabled;
public DialogField() {
fEnabled= true;
fLabel= null;
fLabelText= ""; //$NON-NLS-1$
}
/**
* Sets the label of the dialog field.
*/
public void setLabelText(String labeltext) {
fLabelText= labeltext;
}
// ------ change listener
/**
* Defines the listener for this dialog field.
*/
public final void setDialogFieldListener(IDialogFieldListener listener) {
fDialogFieldListener= listener;
}
/**
* Programatical invocation of a dialog field change.
*/
public void dialogFieldChanged() {
if (fDialogFieldListener != null) {
fDialogFieldListener.dialogFieldChanged(this);
}
}
// ------- focus management
/**
* Tries to set the focus to the dialog field.
* Returns <code>true</code> if the dialog field can take focus.
* To be reimplemented by dialog field implementors.
*/
public boolean setFocus() {
return false;
}
/**
* Posts <code>setFocus</code> to the display event queue.
*/
public void postSetFocusOnDialogField(Display display) {
if (display != null) {
display.asyncExec(
new Runnable() {
public void run() {
setFocus();
}
}
);
}
}
// ------- layout helpers
/**
* Creates all controls of the dialog field and fills it to a composite.
* The composite is assumed to have <code>MGridLayout</code> as
* layout.
* The dialog field will adjust its controls' spans to the number of columns given.
* To be reimplemented by dialog field implementors.
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
assertEnoughColumns(nColumns);
Label label= getLabelControl(parent);
label.setLayoutData(gridDataForLabel(nColumns));
return new Control[] { label };
}
/**
* Returns the number of columns of the dialog field.
* To be reimplemented by dialog field implementors.
*/
public int getNumberOfControls() {
return 1;
}
protected static GridData gridDataForLabel(int span) {
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= span;
return gd;
}
// ------- ui creation
/**
* Creates or returns the created label widget.
* @param parent The parent composite or <code>null</code> if the widget has
* already been created.
*/
public Label getLabelControl(Composite parent) {
if (fLabel == null) {
assertCompositeNotNull(parent);
fLabel= new Label(parent, SWT.LEFT | SWT.WRAP);
fLabel.setFont(parent.getFont());
fLabel.setEnabled(fEnabled);
if (fLabelText != null && !"".equals(fLabelText)) { //$NON-NLS-1$
fLabel.setText(fLabelText);
} else {
// XXX: to avoid a 16 pixel wide empty label - revisit
fLabel.setText("."); //$NON-NLS-1$
fLabel.setVisible(false);
}
}
return fLabel;
}
/**
* Creates a spacer control.
* @param parent The parent composite
*/
public static Control createEmptySpace(Composite parent) {
return createEmptySpace(parent, 1);
}
/**
* Creates a spacer control with the given span.
* The composite is assumed to have <code>MGridLayout</code> as
* layout.
* @param parent The parent composite
*/
public static Control createEmptySpace(Composite parent, int span) {
Label label= new Label(parent, SWT.LEFT);
GridData gd= new GridData();
gd.horizontalAlignment= gd.BEGINNING;
gd.grabExcessHorizontalSpace= false;
gd.horizontalSpan= span;
gd.horizontalIndent= 0;
gd.widthHint= 0;
gd.heightHint= 0;
label.setLayoutData(gd);
return label;
}
/**
* Tests is the control is not <code>null</code> and not disposed.
*/
protected final boolean isOkToUse(Control control) {
return (control != null) && !(control.isDisposed());
}
// --------- enable / disable management
/**
* Sets the enable state of the dialog field.
*/
public final void setEnabled(boolean enabled) {
if (enabled != fEnabled) {
fEnabled= enabled;
updateEnableState();
}
}
/**
* Called when the enable state changed.
* To be extended by dialog field implementors.
*/
protected void updateEnableState() {
if (fLabel != null) {
fLabel.setEnabled(fEnabled);
}
}
/**
* Gets the enable state of the dialog field.
*/
public final boolean isEnabled() {
return fEnabled;
}
protected final void assertCompositeNotNull(Composite comp) {
Assert.isNotNull(comp, "uncreated control requested with composite null"); //$NON-NLS-1$
}
protected final void assertEnoughColumns(int nColumns) {
Assert.isTrue(nColumns >= getNumberOfControls(), "given number of columns is too small"); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,17 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
/**
* Change listener used by <code>DialogField</code>
*/
public interface IDialogFieldListener {
/**
* The dialog field has changed.
*/
void dialogFieldChanged(DialogField field);
}

View file

@ -0,0 +1,22 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
/**
* Change listener used by <code>ListDialogField</code> and <code>CheckedListDialogField</code>
*/
public interface IListAdapter {
/**
* A button from the button bar has been pressed.
*/
void customButtonPressed(DialogField field, int index);
/**
* The selection of the list has changed.
*/
void selectionChanged(DialogField field);
}

View file

@ -0,0 +1,14 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
/**
* Change listener used by <code>StringButtonDialogField</code>
*/
public interface IStringButtonAdapter {
void changeControlPressed(DialogField field);
}

View file

@ -0,0 +1,134 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class LayoutUtil {
/**
* Calculates the number of columns needed by field editors
*/
public static int getNumberOfColumns(DialogField[] editors) {
int nCulumns= 0;
for (int i= 0; i < editors.length; i++) {
nCulumns= Math.max(editors[i].getNumberOfControls(), nCulumns);
}
return nCulumns;
}
/**
* Creates a composite and fills in the given editors.
* @param labelOnTop Defines if the label of all fields should be on top of the fields
*/
public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop) {
doDefaultLayout(parent, editors, labelOnTop, 0, 0, 0, 0);
}
/**
* Creates a composite and fills in the given editors.
* @param labelOnTop Defines if the label of all fields should be on top of the fields
* @param minWidth The minimal width of the composite
* @param minHeight The minimal height of the composite
*/
public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int minWidth, int minHeight) {
doDefaultLayout(parent, editors, labelOnTop, minWidth, minHeight, 0, 0);
}
/**
* Creates a composite and fills in the given editors.
* @param labelOnTop Defines if the label of all fields should be on top of the fields
* @param minWidth The minimal width of the composite
* @param minHeight The minimal height of the composite
* @param marginWidth The margin width to be used by the composite
* @param marginHeight The margin height to be used by the composite
* @deprecated
*/
public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int minWidth, int minHeight, int marginWidth, int marginHeight) {
int nCulumns= getNumberOfColumns(editors);
Control[][] controls= new Control[editors.length][];
for (int i= 0; i < editors.length; i++) {
controls[i]= editors[i].doFillIntoGrid(parent, nCulumns);
}
if (labelOnTop) {
nCulumns--;
modifyLabelSpans(controls, nCulumns);
}
GridLayout layout= new GridLayout();
if (marginWidth != SWT.DEFAULT) {
layout.marginWidth= marginWidth;
}
if (marginHeight != SWT.DEFAULT) {
layout.marginHeight= marginHeight;
}
layout.numColumns= nCulumns;
parent.setLayout(layout);
}
private static void modifyLabelSpans(Control[][] controls, int nCulumns) {
for (int i= 0; i < controls.length; i++) {
setHorizontalSpan(controls[i][0], nCulumns);
}
}
/**
* Sets the span of a control. Assumes that GridData is used.
*/
public static void setHorizontalSpan(Control control, int span) {
Object ld= control.getLayoutData();
if (ld instanceof GridData) {
((GridData)ld).horizontalSpan= span;
} else if (span != 1) {
GridData gd= new GridData();
gd.horizontalSpan= span;
control.setLayoutData(gd);
}
}
/**
* Sets the width hint of a control. Assumes that GridData is used.
*/
public static void setWidthHint(Control control, int widthHint) {
Object ld= control.getLayoutData();
if (ld instanceof GridData) {
((GridData)ld).widthHint= widthHint;
}
}
/**
* Sets the heigthHint hint of a control. Assumes that GridData is used.
*/
public static void setHeigthHint(Control control, int heigthHint) {
Object ld= control.getLayoutData();
if (ld instanceof GridData) {
((GridData)ld).heightHint= heigthHint;
}
}
/**
* Sets the horizontal indent of a control. Assumes that GridData is used.
*/
public static void setHorizontalIndent(Control control, int horizontalIndent) {
Object ld= control.getLayoutData();
if (ld instanceof GridData) {
((GridData)ld).horizontalIndent= horizontalIndent;
}
}
/**
* Sets the horizontal indent of a control. Assumes that GridData is used.
*/
public static void setHorizontalGrabbing(Control control) {
Object ld= control.getLayoutData();
if (ld instanceof GridData) {
((GridData)ld).grabExcessHorizontalSpace= true;
}
}
}

View file

@ -0,0 +1,774 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.internal.ui.PixelConverter;
import org.eclipse.cdt.debug.internal.ui.SWTUtil;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
/**
* A list with a button bar.
* Typical buttons are 'Add', 'Remove', 'Up' and 'Down'.
* List model is independend of widget creation.
* DialogFields controls are: Label, List and Composite containing buttons.
*/
public class ListDialogField extends DialogField {
protected TableViewer fTable;
protected ILabelProvider fLabelProvider;
protected ListViewerAdapter fListViewerAdapter;
protected List fElements;
protected ViewerSorter fViewerSorter;
protected String[] fButtonLabels;
private Button[] fButtonControls;
private boolean[] fButtonsEnabled;
private int fRemoveButtonIndex;
private int fUpButtonIndex;
private int fDownButtonIndex;
private Label fLastSeparator;
private Table fTableControl;
private Composite fButtonsControl;
private ISelection fSelectionWhenEnabled;
private IListAdapter fListAdapter;
private Object fParentElement;
/**
* Creates the <code>ListDialogField</code>.
* @param adapter A listener for button invocation, selection changes.
* @param buttonLabels The labels of all buttons: <code>null</code> is a valid array entry and
* marks a separator.
* @param lprovider The label provider to render the table entries
*/
public ListDialogField(IListAdapter adapter, String[] buttonLabels, ILabelProvider lprovider) {
super();
fListAdapter= adapter;
fLabelProvider= lprovider;
fListViewerAdapter= new ListViewerAdapter();
fParentElement= this;
fElements= new ArrayList(10);
fButtonLabels= buttonLabels;
if (fButtonLabels != null) {
int nButtons= fButtonLabels.length;
fButtonsEnabled= new boolean[nButtons];
for (int i= 0; i < nButtons; i++) {
fButtonsEnabled[i]= true;
}
}
fTable= null;
fTableControl= null;
fButtonsControl= null;
fRemoveButtonIndex= -1;
fUpButtonIndex= -1;
fDownButtonIndex= -1;
}
/**
* Sets the index of the 'remove' button in the button label array passed in the constructor.
* The behaviour of the button marked as the 'remove' button will then be handled internally.
* (enable state, button invocation behaviour)
*/
public void setRemoveButtonIndex(int removeButtonIndex) {
Assert.isTrue(removeButtonIndex < fButtonLabels.length);
fRemoveButtonIndex= removeButtonIndex;
}
/**
* Sets the index of the 'up' button in the button label array passed in the constructor.
* The behaviour of the button marked as the 'up' button will then be handled internally.
* (enable state, button invocation behaviour)
*/
public void setUpButtonIndex(int upButtonIndex) {
Assert.isTrue(upButtonIndex < fButtonLabels.length);
fUpButtonIndex= upButtonIndex;
}
/**
* Sets the index of the 'down' button in the button label array passed in the constructor.
* The behaviour of the button marked as the 'down' button will then be handled internally.
* (enable state, button invocation behaviour)
*/
public void setDownButtonIndex(int downButtonIndex) {
Assert.isTrue(downButtonIndex < fButtonLabels.length);
fDownButtonIndex= downButtonIndex;
}
/**
* Sets the viewerSorter.
* @param viewerSorter The viewerSorter to set
*/
public void setViewerSorter(ViewerSorter viewerSorter) {
fViewerSorter= viewerSorter;
}
// ------ adapter communication
private void buttonPressed(int index) {
if (!managedButtonPressed(index)) {
fListAdapter.customButtonPressed(this, index);
}
}
/**
* Checks if the button pressed is handled internally
* @return Returns true if button has been handled.
*/
protected boolean managedButtonPressed(int index) {
if (index == fRemoveButtonIndex) {
remove();
} else if (index == fUpButtonIndex) {
up();
} else if (index == fDownButtonIndex) {
down();
} else {
return false;
}
return true;
}
// ------ layout helpers
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
PixelConverter converter= new PixelConverter(parent);
assertEnoughColumns(nColumns);
Label label= getLabelControl(parent);
GridData gd= gridDataForLabel(1);
gd.verticalAlignment= gd.BEGINNING;
label.setLayoutData(gd);
Control list= getListControl(parent);
gd= new GridData();
gd.horizontalAlignment= gd.FILL;
gd.grabExcessHorizontalSpace= false;
gd.verticalAlignment= gd.FILL;
gd.grabExcessVerticalSpace= true;
gd.horizontalSpan= nColumns - 2;
gd.widthHint= converter.convertWidthInCharsToPixels(50);
gd.heightHint= converter.convertHeightInCharsToPixels(6);
list.setLayoutData(gd);
Composite buttons= getButtonBox(parent);
gd= new GridData();
gd.horizontalAlignment= gd.FILL;
gd.grabExcessHorizontalSpace= false;
gd.verticalAlignment= gd.FILL;
gd.grabExcessVerticalSpace= true;
gd.horizontalSpan= 1;
buttons.setLayoutData(gd);
return new Control[] { label, list, buttons };
}
/*
* @see DialogField#getNumberOfControls
*/
public int getNumberOfControls() {
return 3;
}
/**
* Sets the minimal width of the buttons. Must be called after widget creation.
*/
public void setButtonsMinWidth(int minWidth) {
if (fLastSeparator != null) {
((GridData)fLastSeparator.getLayoutData()).widthHint= minWidth;
}
}
// ------ ui creation
/**
* Returns the list control. When called the first time, the control will be created.
* @param The parent composite when called the first time, or <code>null</code>
* after.
*/
public Control getListControl(Composite parent) {
if (fTableControl == null) {
assertCompositeNotNull(parent);
fTable= createTableViewer(parent);
fTable.setContentProvider(fListViewerAdapter);
fTable.setLabelProvider(fLabelProvider);
fTable.addSelectionChangedListener(fListViewerAdapter);
fTableControl= (Table)fTable.getControl();
fTable.setInput(fParentElement);
if (fViewerSorter != null) {
fTable.setSorter(fViewerSorter);
}
fTableControl.setEnabled(isEnabled());
if (fSelectionWhenEnabled != null) {
postSetSelection(fSelectionWhenEnabled);
}
}
return fTableControl;
}
/**
* Returns the internally used table viewer.
*/
public TableViewer getTableViewer() {
return fTable;
}
/*
* Subclasses may override to specify a different style.
*/
protected int getListStyle(){
return SWT.BORDER + SWT.MULTI + SWT.H_SCROLL + SWT.V_SCROLL;
}
protected TableViewer createTableViewer(Composite parent) {
Table table= new Table(parent, getListStyle());
return new TableViewer(table);
}
protected Button createButton(Composite parent, String label, SelectionListener listener) {
Button button= new Button(parent, SWT.PUSH);
button.setText(label);
button.addSelectionListener(listener);
GridData gd= new GridData();
gd.horizontalAlignment= gd.FILL;
gd.grabExcessHorizontalSpace= true;
gd.verticalAlignment= gd.BEGINNING;
gd.heightHint = SWTUtil.getButtonHeigthHint(button);
gd.widthHint = SWTUtil.getButtonWidthHint(button);
button.setLayoutData(gd);
return button;
}
private Label createSeparator(Composite parent) {
Label separator= new Label(parent, SWT.NONE);
separator.setVisible(false);
GridData gd= new GridData();
gd.horizontalAlignment= gd.FILL;
gd.verticalAlignment= gd.BEGINNING;
gd.heightHint= 4;
separator.setLayoutData(gd);
return separator;
}
/**
* Returns the composite containing the buttons. When called the first time, the control
* will be created.
* @param The parent composite when called the first time, or <code>null</code>
* after.
*/
public Composite getButtonBox(Composite parent) {
if (fButtonsControl == null) {
assertCompositeNotNull(parent);
SelectionListener listener= new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
doButtonSelected(e);
}
public void widgetSelected(SelectionEvent e) {
doButtonSelected(e);
}
};
Composite contents= new Composite(parent, SWT.NULL);
GridLayout layout= new GridLayout();
layout.marginWidth= 0;
layout.marginHeight= 0;
contents.setLayout(layout);
if (fButtonLabels != null) {
fButtonControls= new Button[fButtonLabels.length];
for (int i= 0; i < fButtonLabels.length; i++) {
String currLabel= fButtonLabels[i];
if (currLabel != null) {
fButtonControls[i]= createButton(contents, currLabel, listener);
fButtonControls[i].setEnabled(isEnabled() && fButtonsEnabled[i]);
} else {
fButtonControls[i]= null;
createSeparator(contents);
}
}
}
fLastSeparator= createSeparator(contents);
updateButtonState();
fButtonsControl= contents;
}
return fButtonsControl;
}
private void doButtonSelected(SelectionEvent e) {
if (fButtonControls != null) {
for (int i= 0; i < fButtonControls.length; i++) {
if (e.widget == fButtonControls[i]) {
buttonPressed(i);
return;
}
}
}
}
// ------ enable / disable management
/*
* @see DialogField#dialogFieldChanged
*/
public void dialogFieldChanged() {
super.dialogFieldChanged();
updateButtonState();
}
private Button getButton(int index) {
if (fButtonControls != null && index >= 0 && index < fButtonControls.length) {
return fButtonControls[index];
}
return null;
}
/*
* Updates the enable state of the all buttons
*/
protected void updateButtonState() {
if (fButtonControls != null) {
ISelection sel= fTable.getSelection();
for (int i= 0; i < fButtonControls.length; i++) {
Button button= fButtonControls[i];
if (isOkToUse(button)) {
boolean extraState= getManagedButtonState(sel, i);
button.setEnabled(isEnabled() && extraState && fButtonsEnabled[i]);
}
}
}
}
protected boolean getManagedButtonState(ISelection sel, int index) {
if (index == fRemoveButtonIndex) {
return !sel.isEmpty();
} else if (index == fUpButtonIndex) {
return !sel.isEmpty() && canMoveUp();
} else if (index == fDownButtonIndex) {
return !sel.isEmpty() && canMoveDown();
}
return true;
}
/*
* @see DialogField#updateEnableState
*/
protected void updateEnableState() {
super.updateEnableState();
boolean enabled= isEnabled();
if (isOkToUse(fTableControl)) {
if (!enabled) {
fSelectionWhenEnabled= fTable.getSelection();
selectElements(null);
} else {
selectElements(fSelectionWhenEnabled);
fSelectionWhenEnabled= null;
}
fTableControl.setEnabled(enabled);
}
updateButtonState();
}
/**
* Sets a button enabled or disabled.
*/
public void enableButton(int index, boolean enable) {
if (fButtonsEnabled != null && index < fButtonsEnabled.length) {
fButtonsEnabled[index]= enable;
updateButtonState();
}
}
// ------ model access
/**
* Sets the elements shown in the list.
*/
public void setElements(List elements) {
fElements= new ArrayList(elements);
if (fTable != null) {
fTable.refresh();
}
dialogFieldChanged();
}
/**
* Gets the elements shown in the list.
* The list returned is a copy, so it can be modified by the user.
*/
public List getElements() {
return new ArrayList(fElements);
}
/**
* Gets the elements shown at the given index.
*/
public Object getElement(int index) {
return fElements.get(index);
}
/**
* Replace an element.
*/
public void replaceElement(Object oldElement, Object newElement) throws IllegalArgumentException {
int idx= fElements.indexOf(oldElement);
if (idx != -1) {
if (oldElement.equals(newElement) || fElements.contains(newElement)) {
return;
}
fElements.set(idx, newElement);
if (fTable != null) {
List selected= getSelectedElements();
if (selected.remove(oldElement)) {
selected.add(newElement);
}
fTable.refresh();
selectElements(new StructuredSelection(selected));
}
dialogFieldChanged();
} else {
throw new IllegalArgumentException();
}
}
/**
* Adds an element at the end of the list.
*/
public void addElement(Object element) {
if (fElements.contains(element)) {
return;
}
fElements.add(element);
if (fTable != null) {
fTable.add(element);
}
dialogFieldChanged();
}
/**
* Adds elements at the end of the list.
*/
public void addElements(List elements) {
int nElements= elements.size();
if (nElements > 0) {
// filter duplicated
ArrayList elementsToAdd= new ArrayList(nElements);
for (int i= 0; i < nElements; i++) {
Object elem= elements.get(i);
if (!fElements.contains(elem)) {
elementsToAdd.add(elem);
}
}
fElements.addAll(elementsToAdd);
if (fTable != null) {
fTable.add(elementsToAdd.toArray());
}
dialogFieldChanged();
}
}
/**
* Adds an element at a position.
*/
public void insertElementAt(Object element, int index) {
if (fElements.contains(element)) {
return;
}
fElements.add(index, element);
if (fTable != null) {
fTable.add(element);
}
dialogFieldChanged();
}
/**
* Adds an element at a position.
*/
public void removeAllElements() {
if (fElements.size() > 0) {
fElements.clear();
if (fTable != null) {
fTable.refresh();
}
dialogFieldChanged();
}
}
/**
* Removes an element from the list.
*/
public void removeElement(Object element) throws IllegalArgumentException {
if (fElements.remove(element)) {
if (fTable != null) {
fTable.remove(element);
}
dialogFieldChanged();
} else {
throw new IllegalArgumentException();
}
}
/**
* Removes elements from the list.
*/
public void removeElements(List elements) {
if (elements.size() > 0) {
fElements.removeAll(elements);
if (fTable != null) {
fTable.remove(elements.toArray());
}
dialogFieldChanged();
}
}
/**
* Gets the number of elements
*/
public int getSize() {
return fElements.size();
}
public void selectElements(ISelection selection) {
fSelectionWhenEnabled= selection;
if (fTable != null) {
fTable.setSelection(selection, true);
}
}
public void selectFirstElement() {
Object element= null;
if (fViewerSorter != null) {
Object[] arr= fElements.toArray();
fViewerSorter.sort(fTable, arr);
if (arr.length > 0) {
element= arr[0];
}
} else {
if (fElements.size() > 0) {
element= fElements.get(0);
}
}
if (element != null) {
selectElements(new StructuredSelection(element));
}
}
public void postSetSelection(final ISelection selection) {
if (isOkToUse(fTableControl)) {
Display d= fTableControl.getDisplay();
d.asyncExec(new Runnable() {
public void run() {
if (isOkToUse(fTableControl)) {
selectElements(selection);
}
}
});
}
}
/**
* Refreshes the table.
*/
public void refresh() {
fTable.refresh();
}
// ------- list maintenance
private List moveUp(List elements, List move) {
int nElements= elements.size();
List res= new ArrayList(nElements);
Object floating= null;
for (int i= 0; i < nElements; i++) {
Object curr= elements.get(i);
if (move.contains(curr)) {
res.add(curr);
} else {
if (floating != null) {
res.add(floating);
}
floating= curr;
}
}
if (floating != null) {
res.add(floating);
}
return res;
}
private void moveUp(List toMoveUp) {
if (toMoveUp.size() > 0) {
setElements(moveUp(fElements, toMoveUp));
fTable.reveal(toMoveUp.get(0));
}
}
private void moveDown(List toMoveDown) {
if (toMoveDown.size() > 0) {
setElements(reverse(moveUp(reverse(fElements), toMoveDown)));
fTable.reveal(toMoveDown.get(toMoveDown.size() - 1));
}
}
private List reverse(List p) {
List reverse= new ArrayList(p.size());
for (int i= p.size()-1; i >= 0; i--) {
reverse.add(p.get(i));
}
return reverse;
}
private void remove() {
removeElements(getSelectedElements());
}
private void up() {
moveUp(getSelectedElements());
}
private void down() {
moveDown(getSelectedElements());
}
private boolean canMoveUp() {
if (isOkToUse(fTableControl)) {
int[] indc= fTableControl.getSelectionIndices();
for (int i= 0; i < indc.length; i++) {
if (indc[i] != i) {
return true;
}
}
}
return false;
}
private boolean canMoveDown() {
if (isOkToUse(fTableControl)) {
int[] indc= fTableControl.getSelectionIndices();
int k= fElements.size() - 1;
for (int i= indc.length - 1; i >= 0 ; i--, k--) {
if (indc[i] != k) {
return true;
}
}
}
return false;
}
/**
* Returns the selected elements.
*/
public List getSelectedElements() {
List result= new ArrayList();
if (fTable != null) {
ISelection selection= fTable.getSelection();
if (selection instanceof IStructuredSelection) {
Iterator iter= ((IStructuredSelection)selection).iterator();
while (iter.hasNext()) {
result.add(iter.next());
}
}
}
return result;
}
// ------- ListViewerAdapter
private class ListViewerAdapter implements IStructuredContentProvider, ISelectionChangedListener {
// ------- ITableContentProvider Interface ------------
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// will never happen
}
public boolean isDeleted(Object element) {
return false;
}
public void dispose() {
}
public Object[] getElements(Object obj) {
return fElements.toArray();
}
// ------- ISelectionChangedListener Interface ------------
public void selectionChanged(SelectionChangedEvent event) {
doListSelected(event);
}
}
private void doListSelected(SelectionChangedEvent event) {
updateButtonState();
if (fListAdapter != null) {
fListAdapter.selectionChanged(this);
}
}
}

View file

@ -0,0 +1,185 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.cdt.debug.internal.ui.SWTUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* Dialog Field containing a single button: e.g. radio or checkbox button.
*/
public class SelectionButtonDialogField extends DialogField {
private Button fButton;
private boolean fIsSelected;
private DialogField[] fAttachedDialogFields;
private int fButtonStyle;
/**
* Creates a selection button.
* Allowed button styles: SWT.RADIO, SWT.CHECK, SWT.TOGGLE, SWT.PUSH
*/
public SelectionButtonDialogField(int buttonStyle) {
super();
fIsSelected= false;
fAttachedDialogFields= null;
fButtonStyle= buttonStyle;
}
/**
* Attaches a field to the selection state of the selection button.
* The attached field will be disabled if the selection button is not selected.
*/
public void attachDialogField(DialogField dialogField) {
attachDialogFields(new DialogField[] { dialogField });
}
/**
* Attaches fields to the selection state of the selection button.
* The attached fields will be disabled if the selection button is not selected.
*/
public void attachDialogFields(DialogField[] dialogFields) {
fAttachedDialogFields= dialogFields;
for (int i= 0; i < dialogFields.length; i++) {
dialogFields[i].setEnabled(fIsSelected);
}
}
/**
* Returns <code>true</code> is teh gived field is attached to the selection button.
*/
public boolean isAttached(DialogField editor) {
if (fAttachedDialogFields != null) {
for (int i=0; i < fAttachedDialogFields.length; i++) {
if (fAttachedDialogFields[i] == editor) {
return true;
}
}
}
return false;
}
// ------- layout helpers
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
assertEnoughColumns(nColumns);
Button button= getSelectionButton(parent);
GridData gd= new GridData();
gd.horizontalSpan= nColumns;
gd.horizontalAlignment= gd.FILL;
if (fButtonStyle == SWT.PUSH) {
gd.heightHint = SWTUtil.getButtonHeigthHint(button);
gd.widthHint = SWTUtil.getButtonWidthHint(button);
}
button.setLayoutData(gd);
return new Control[] { button };
}
/*
* @see DialogField#getNumberOfControls
*/
public int getNumberOfControls() {
return 1;
}
// ------- ui creation
/**
* Returns the selection button widget. When called the first time, the widget will be created.
* @param The parent composite when called the first time, or <code>null</code>
* after.
*/
public Button getSelectionButton(Composite group) {
if (fButton == null) {
assertCompositeNotNull(group);
fButton= new Button(group, fButtonStyle);
fButton.setFont(group.getFont());
fButton.setText(fLabelText);
fButton.setEnabled(isEnabled());
fButton.setSelection(fIsSelected);
fButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
doWidgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
doWidgetSelected(e);
}
});
}
return fButton;
}
private void doWidgetSelected(SelectionEvent e) {
if (isOkToUse(fButton)) {
changeValue(fButton.getSelection());
}
}
private void changeValue(boolean newState) {
if (fIsSelected != newState) {
fIsSelected= newState;
if (fAttachedDialogFields != null) {
boolean focusSet= false;
for (int i= 0; i < fAttachedDialogFields.length; i++) {
fAttachedDialogFields[i].setEnabled(fIsSelected);
if (fIsSelected && !focusSet) {
focusSet= fAttachedDialogFields[i].setFocus();
}
}
}
dialogFieldChanged();
} else if (fButtonStyle == SWT.PUSH) {
dialogFieldChanged();
}
}
// ------ model access
/**
* Returns the selection state of the button.
*/
public boolean isSelected() {
return fIsSelected;
}
/**
* Sets the selection state of the button.
*/
public void setSelection(boolean selected) {
changeValue(selected);
if (isOkToUse(fButton)) {
fButton.setSelection(selected);
}
}
// ------ enable / disable management
/*
* @see DialogField#updateEnableState
*/
protected void updateEnableState() {
super.updateEnableState();
if (isOkToUse(fButton)) {
fButton.setEnabled(isEnabled());
}
}
}

View file

@ -0,0 +1,250 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.jface.util.Assert;
/**
* Dialog field describing a group with buttons (Checkboxes, radio buttons..)
*/
public class SelectionButtonDialogFieldGroup extends DialogField {
private Composite fButtonComposite;
private Button[] fButtons;
private String[] fButtonNames;
private boolean[] fButtonsSelected;
private boolean[] fButtonsEnabled;
private int fGroupBorderStyle;
private int fGroupNumberOfColumns;
private int fButtonsStyle;
/**
* Creates a group without border.
*/
public SelectionButtonDialogFieldGroup(int buttonsStyle, String[] buttonNames, int nColumns) {
this(buttonsStyle, buttonNames, nColumns, SWT.NONE);
}
/**
* Creates a group with border (label in border).
* Accepted button styles are: SWT.RADIO, SWT.CHECK, SWT.TOGGLE
* For border styles see <code>Group</code>
*/
public SelectionButtonDialogFieldGroup(int buttonsStyle, String[] buttonNames, int nColumns, int borderStyle) {
super();
Assert.isTrue(buttonsStyle == SWT.RADIO || buttonsStyle == SWT.CHECK || buttonsStyle == SWT.TOGGLE);
fButtonNames= buttonNames;
int nButtons= buttonNames.length;
fButtonsSelected= new boolean[nButtons];
fButtonsEnabled= new boolean[nButtons];
for (int i= 0; i < nButtons; i++) {
fButtonsSelected[i]= false;
fButtonsEnabled[i]= true;
}
if (fButtonsStyle == SWT.RADIO) {
fButtonsSelected[0]= true;
}
fGroupBorderStyle= borderStyle;
fGroupNumberOfColumns= (nColumns <= 0) ? nButtons : nColumns;
fButtonsStyle= buttonsStyle;
}
// ------- layout helpers
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
assertEnoughColumns(nColumns);
if (fGroupBorderStyle == SWT.NONE) {
Label label= getLabelControl(parent);
label.setLayoutData(gridDataForLabel(1));
Composite buttonsgroup= getSelectionButtonsGroup(parent);
GridData gd= new GridData();
gd.horizontalSpan= nColumns - 1;
buttonsgroup.setLayoutData(gd);
return new Control[] { label, buttonsgroup };
} else {
Composite buttonsgroup= getSelectionButtonsGroup(parent);
GridData gd= new GridData();
gd.horizontalSpan= nColumns;
buttonsgroup.setLayoutData(gd);
return new Control[] { buttonsgroup };
}
}
/*
* @see DialogField#doFillIntoGrid
*/
public int getNumberOfControls() {
return (fGroupBorderStyle == SWT.NONE) ? 2 : 1;
}
// ------- ui creation
private Button createSelectionButton(int index, Composite group, SelectionListener listener) {
Button button= new Button(group, fButtonsStyle | SWT.LEFT);
button.setFont(group.getFont());
button.setText(fButtonNames[index]);
button.setEnabled(isEnabled() && fButtonsEnabled[index]);
button.setSelection(fButtonsSelected[index]);
button.addSelectionListener(listener);
button.setLayoutData(new GridData());
return button;
}
/**
* Returns the group widget. When called the first time, the widget will be created.
* @param The parent composite when called the first time, or <code>null</code>
* after.
*/
public Composite getSelectionButtonsGroup(Composite parent) {
if (fButtonComposite == null) {
assertCompositeNotNull(parent);
GridLayout layout= new GridLayout();
layout.makeColumnsEqualWidth= true;
layout.numColumns= fGroupNumberOfColumns;
if (fGroupBorderStyle != SWT.NONE) {
Group group= new Group(parent, fGroupBorderStyle);
if (fLabelText != null && fLabelText.length() > 0) {
group.setText(fLabelText);
}
fButtonComposite= group;
} else {
fButtonComposite= new Composite(parent, SWT.NULL);
layout.marginHeight= 0;
layout.marginWidth= 0;
}
fButtonComposite.setLayout(layout);
SelectionListener listener= new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
doWidgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
doWidgetSelected(e);
}
};
int nButtons= fButtonNames.length;
fButtons= new Button[nButtons];
for (int i= 0; i < nButtons; i++) {
fButtons[i]= createSelectionButton(i, fButtonComposite, listener);
}
int nRows= nButtons / fGroupNumberOfColumns;
int nFillElements= nRows * fGroupNumberOfColumns - nButtons;
for (int i= 0; i < nFillElements; i++) {
createEmptySpace(fButtonComposite);
}
}
return fButtonComposite;
}
/**
* Returns a button from the group or <code>null</code> if not yet created.
*/
public Button getSelectionButton(int index) {
if (index >= 0 && index < fButtons.length) {
return fButtons[index];
}
return null;
}
private void doWidgetSelected(SelectionEvent e) {
Button button= (Button)e.widget;
for (int i= 0; i < fButtons.length; i++) {
if (fButtons[i] == button) {
fButtonsSelected[i]= button.getSelection();
dialogFieldChanged();
return;
}
}
}
// ------ model access
/**
* Returns the selection state of a button contained in the group.
* @param The index of the button
*/
public boolean isSelected(int index) {
if (index >= 0 && index < fButtonsSelected.length) {
return fButtonsSelected[index];
}
return false;
}
/**
* Sets the selection state of a button contained in the group.
*/
public void setSelection(int index, boolean selected) {
if (index >= 0 && index < fButtonsSelected.length) {
if (fButtonsSelected[index] != selected) {
fButtonsSelected[index]= selected;
if (fButtons != null) {
Button button= fButtons[index];
if (isOkToUse(button)) {
button.setSelection(selected);
}
}
}
}
}
// ------ enable / disable management
protected void updateEnableState() {
super.updateEnableState();
if (fButtons != null) {
boolean enabled= isEnabled();
for (int i= 0; i < fButtons.length; i++) {
Button button= fButtons[i];
if (isOkToUse(button)) {
button.setEnabled(enabled && fButtonsEnabled[i]);
}
}
}
}
/**
* Sets the enable state of a button contained in the group.
*/
public void enableSelectionButton(int index, boolean enable) {
if (index >= 0 && index < fButtonsEnabled.length) {
fButtonsEnabled[index]= enable;
if (fButtons != null) {
Button button= fButtons[index];
if (isOkToUse(button)) {
button.setEnabled(isEnabled() && enable);
}
}
}
}
}

View file

@ -0,0 +1,88 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.GridData;
/**
* Dialog field describing a separator.
*/
public class Separator extends DialogField {
private Label fSeparator;
private int fStyle;
public Separator() {
this(SWT.NONE);
}
/**
* @param style of the separator. See <code>Label</code> for possible
* styles.
*/
public Separator(int style) {
super();
fStyle= style;
}
// ------- layout helpers
/**
* Creates the separator and fills it in a MGridLayout.
* @param height The heigth of the separator
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns, int height) {
assertEnoughColumns(nColumns);
Control separator= getSeparator(parent);
separator.setLayoutData(gridDataForSeperator(nColumns, height));
return new Control[] { separator };
}
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
return doFillIntoGrid(parent, nColumns, 4);
}
/*
* @see DialogField#getNumberOfControls
*/
public int getNumberOfControls() {
return 1;
}
protected static GridData gridDataForSeperator(int span, int height) {
GridData gd= new GridData();
gd.horizontalAlignment= gd.FILL;
gd.verticalAlignment= gd.BEGINNING;
gd.heightHint= height;
gd.horizontalSpan= span;
return gd;
}
// ------- ui creation
/**
* Creates or returns the created separator.
* @param parent The parent composite or <code>null</code> if the widget has
* already been created.
*/
public Control getSeparator(Composite parent) {
if (fSeparator == null) {
assertCompositeNotNull(parent);
fSeparator= new Label(parent, fStyle);
}
return fSeparator;
}
}

View file

@ -0,0 +1,135 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.cdt.debug.internal.ui.SWTUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
/**
* Dialog field containing a label, text control and a button control.
*/
public class StringButtonDialogField extends StringDialogField {
private Button fBrowseButton;
private String fBrowseButtonLabel;
private IStringButtonAdapter fStringButtonAdapter;
private boolean fButtonEnabled;
public StringButtonDialogField(IStringButtonAdapter adapter) {
super();
fStringButtonAdapter= adapter;
fBrowseButtonLabel= "!Browse...!"; //$NON-NLS-1$
fButtonEnabled= true;
}
/**
* Sets the label of the button.
*/
public void setButtonLabel(String label) {
fBrowseButtonLabel= label;
}
// ------ adapter communication
/**
* Programmatical pressing of the button
*/
public void changeControlPressed() {
fStringButtonAdapter.changeControlPressed(this);
}
// ------- layout helpers
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
assertEnoughColumns(nColumns);
Label label= getLabelControl(parent);
label.setLayoutData(gridDataForLabel(1));
Text text= getTextControl(parent);
text.setLayoutData(gridDataForText(nColumns - 2));
Button button= getChangeControl(parent);
button.setLayoutData(gridDataForButton(button, 1));
return new Control[] { label, text, button };
}
/*
* @see DialogField#getNumberOfControls
*/
public int getNumberOfControls() {
return 3;
}
protected static GridData gridDataForButton(Button button, int span) {
GridData gd= new GridData();
gd.horizontalAlignment= gd.FILL;
gd.grabExcessHorizontalSpace= false;
gd.horizontalSpan= span;
gd.heightHint = SWTUtil.getButtonHeigthHint(button);
gd.widthHint = SWTUtil.getButtonWidthHint(button);
return gd;
}
// ------- ui creation
/**
* Creates or returns the created buttom widget.
* @param parent The parent composite or <code>null</code> if the widget has
* already been created.
*/
public Button getChangeControl(Composite parent) {
if (fBrowseButton == null) {
assertCompositeNotNull(parent);
fBrowseButton= new Button(parent, SWT.PUSH);
fBrowseButton.setText(fBrowseButtonLabel);
fBrowseButton.setEnabled(isEnabled() && fButtonEnabled);
fBrowseButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
changeControlPressed();
}
public void widgetSelected(SelectionEvent e) {
changeControlPressed();
}
});
}
return fBrowseButton;
}
// ------ enable / disable management
/**
* Sets the enable state of the button.
*/
public void enableButton(boolean enable) {
if (isOkToUse(fBrowseButton)) {
fBrowseButton.setEnabled(isEnabled() && enable);
}
fButtonEnabled= enable;
}
/*
* @see DialogField#updateEnableState
*/
protected void updateEnableState() {
super.updateEnableState();
if (isOkToUse(fBrowseButton)) {
fBrowseButton.setEnabled(isEnabled() && fButtonEnabled);
}
}
}

View file

@ -0,0 +1,161 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;
/**
* Dialog field containing a label, text control, status label and a button control.
* The status label can be either a image or text label, and can be usd to give
* additional information about the current element chosen.
*/
public class StringButtonStatusDialogField extends StringButtonDialogField {
private Label fStatusLabelControl;
private Object fStatus; // String or ImageDescriptor
private String fWidthHintString;
private int fWidthHint;
public StringButtonStatusDialogField(IStringButtonAdapter adapter) {
super(adapter);
fStatus= null;
fWidthHintString= null;
fWidthHint= -1;
}
// ------ set status
/**
* Sets the status string.
*/
public void setStatus(String status) {
if (isOkToUse(fStatusLabelControl)) {
fStatusLabelControl.setText(status);
}
fStatus= status;
}
/**
* Sets the status image.
* Caller is responsible to dispose image
*/
public void setStatus(Image image) {
if (isOkToUse(fStatusLabelControl)) {
if (image == null) {
fStatusLabelControl.setImage(null);
} else {
fStatusLabelControl.setImage(image);
}
}
fStatus= image;
}
/**
* Sets the staus string hint of the status label.
* The string is used to calculate the size of the status label.
*/
public void setStatusWidthHint(String widthHintString) {
fWidthHintString= widthHintString;
fWidthHint= -1;
}
/**
* Sets the width hint of the status label.
*/
public void setStatusWidthHint(int widthHint) {
fWidthHint= widthHint;
fWidthHintString= null;
}
// ------- layout helpers
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
assertEnoughColumns(nColumns);
Label label= getLabelControl(parent);
label.setLayoutData(gridDataForLabel(1));
Text text= getTextControl(parent);
text.setLayoutData(gridDataForText(nColumns - 3));
Label status= getStatusLabelControl(parent);
status.setLayoutData(gridDataForStatusLabel(parent, 1));
Button button= getChangeControl(parent);
button.setLayoutData(gridDataForButton(button, 1));
return new Control[] { label, text, status, button };
}
/*
* @see DialogField#getNumberOfControls
*/
public int getNumberOfControls() {
return 4;
}
protected GridData gridDataForStatusLabel(Control aControl, int span) {
GridData gd= new GridData();
gd.horizontalAlignment= gd.BEGINNING;
gd.grabExcessHorizontalSpace= false;
gd.horizontalIndent= 0;
if (fWidthHintString != null) {
GC gc= new GC(aControl);
gd.widthHint= gc.textExtent(fWidthHintString).x;
gc.dispose();
} else if (fWidthHint != -1) {
gd.widthHint= fWidthHint;
} else {
gd.widthHint= SWT.DEFAULT;
}
return gd;
}
// ------- ui creation
/**
* Creates or returns the created status label widget.
* @param parent The parent composite or <code>null</code> when the widget has
* already been created.
*/
public Label getStatusLabelControl(Composite parent) {
if (fStatusLabelControl == null) {
assertCompositeNotNull(parent);
fStatusLabelControl= new Label(parent, SWT.LEFT);
fStatusLabelControl.setFont(parent.getFont());
fStatusLabelControl.setEnabled(isEnabled());
if (fStatus instanceof Image) {
fStatusLabelControl.setImage((Image)fStatus);
} else if (fStatus instanceof String) {
fStatusLabelControl.setText((String)fStatus);
} else {
// must be null
}
}
return fStatusLabelControl;
}
// ------ enable / disable management
/*
* @see DialogField#updateEnableState
*/
protected void updateEnableState() {
super.updateEnableState();
if (isOkToUse(fStatusLabelControl)) {
fStatusLabelControl.setEnabled(isEnabled());
}
}
}

View file

@ -0,0 +1,153 @@
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
/**
* Dialog field containing a label and a text control.
*/
public class StringDialogField extends DialogField {
private String fText;
private Text fTextControl;
private ModifyListener fModifyListener;
public StringDialogField() {
super();
fText= ""; //$NON-NLS-1$
}
// ------- layout helpers
/*
* @see DialogField#doFillIntoGrid
*/
public Control[] doFillIntoGrid(Composite parent, int nColumns) {
assertEnoughColumns(nColumns);
Label label= getLabelControl(parent);
label.setLayoutData(gridDataForLabel(1));
Text text= getTextControl(parent);
text.setLayoutData(gridDataForText(nColumns - 1));
return new Control[] { label, text };
}
/*
* @see DialogField#getNumberOfControls
*/
public int getNumberOfControls() {
return 2;
}
protected static GridData gridDataForText(int span) {
GridData gd= new GridData();
gd.horizontalAlignment= gd.FILL;
gd.grabExcessHorizontalSpace= false;
gd.horizontalSpan= span;
return gd;
}
// ------- focus methods
/*
* @see DialogField#setFocus
*/
public boolean setFocus() {
if (isOkToUse(fTextControl)) {
fTextControl.setFocus();
fTextControl.setSelection(0, fTextControl.getText().length());
}
return true;
}
// ------- ui creation
/**
* Creates or returns the created text control.
* @param parent The parent composite or <code>null</code> when the widget has
* already been created.
*/
public Text getTextControl(Composite parent) {
if (fTextControl == null) {
assertCompositeNotNull(parent);
fModifyListener= new ModifyListener() {
public void modifyText(ModifyEvent e) {
doModifyText(e);
}
};
fTextControl= new Text(parent, SWT.SINGLE | SWT.BORDER);
// moved up due to 1GEUNW2
fTextControl.setText(fText);
fTextControl.setFont(parent.getFont());
fTextControl.addModifyListener(fModifyListener);
fTextControl.setEnabled(isEnabled());
}
return fTextControl;
}
private void doModifyText(ModifyEvent e) {
if (isOkToUse(fTextControl)) {
fText= fTextControl.getText();
}
dialogFieldChanged();
}
// ------ enable / disable management
/*
* @see DialogField#updateEnableState
*/
protected void updateEnableState() {
super.updateEnableState();
if (isOkToUse(fTextControl)) {
fTextControl.setEnabled(isEnabled());
}
}
// ------ text access
/**
* Gets the text. Can not be <code>null</code>
*/
public String getText() {
return fText;
}
/**
* Sets the text. Triggers a dialog-changed event.
*/
public void setText(String text) {
fText= text;
if (isOkToUse(fTextControl)) {
fTextControl.setText(text);
} else {
dialogFieldChanged();
}
}
/**
* Sets the text without triggering a dialog-changed event.
*/
public void setTextWithoutUpdate(String text) {
fText= text;
if (isOkToUse(fTextControl)) {
fTextControl.removeModifyListener(fModifyListener);
fTextControl.setText(text);
fTextControl.addModifyListener(fModifyListener);
}
}
}