mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
Fix all the synthetic method warning from Eclipse.
New addition CheckedListDialogField.
This commit is contained in:
parent
237f613643
commit
db710bebea
7 changed files with 237 additions and 21 deletions
|
@ -0,0 +1,216 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.ui.wizards.dialogfields;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Control;
|
||||||
|
import org.eclipse.swt.widgets.Table;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 is 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -122,7 +122,7 @@ public class ComboDialogField extends DialogField {
|
||||||
return fComboControl;
|
return fComboControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doModifyText(ModifyEvent e) {
|
protected void doModifyText(ModifyEvent e) {
|
||||||
if (isOkToUse(fComboControl)) {
|
if (isOkToUse(fComboControl)) {
|
||||||
fText= fComboControl.getText();
|
fText= fComboControl.getText();
|
||||||
fSelectionIndex= fComboControl.getSelectionIndex();
|
fSelectionIndex= fComboControl.getSelectionIndex();
|
||||||
|
@ -130,7 +130,7 @@ public class ComboDialogField extends DialogField {
|
||||||
dialogFieldChanged();
|
dialogFieldChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doSelectionChanged(SelectionEvent e) {
|
protected void doSelectionChanged(SelectionEvent e) {
|
||||||
if (isOkToUse(fComboControl)) {
|
if (isOkToUse(fComboControl)) {
|
||||||
fItems= fComboControl.getItems();
|
fItems= fComboControl.getItems();
|
||||||
fText= fComboControl.getText();
|
fText= fComboControl.getText();
|
||||||
|
|
|
@ -46,20 +46,20 @@ import org.eclipse.ui.internal.dialogs.PathVariableSelectionDialog;
|
||||||
*/
|
*/
|
||||||
public class LinkToFileGroup extends StringButtonDialogField {
|
public class LinkToFileGroup extends StringButtonDialogField {
|
||||||
private String fText;
|
private String fText;
|
||||||
private Listener listener;
|
protected Listener listener;
|
||||||
private String initialLinkTarget;
|
private String initialLinkTarget;
|
||||||
private int type;
|
private int type;
|
||||||
private boolean createLink = false;
|
protected boolean createLink = false;
|
||||||
|
|
||||||
// used to compute layout sizes
|
// used to compute layout sizes
|
||||||
//private FontMetrics fontMetrics;
|
//private FontMetrics fontMetrics;
|
||||||
|
|
||||||
// widgets
|
// widgets
|
||||||
//private Composite groupComposite;
|
//private Composite groupComposite;
|
||||||
private Text linkTargetField;
|
protected Text linkTargetField;
|
||||||
private Button linkButton;
|
protected Button linkButton;
|
||||||
private Button browseButton;
|
protected Button browseButton;
|
||||||
private Button variablesButton;
|
protected Button variablesButton;
|
||||||
private Label resolvedPathLabelText;
|
private Label resolvedPathLabelText;
|
||||||
private Label resolvedPathLabelData;
|
private Label resolvedPathLabelData;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class LinkToFileGroup extends StringButtonDialogField {
|
||||||
Label label= getLabelControl(parent);
|
Label label= getLabelControl(parent);
|
||||||
label.setLayoutData(gridDataForLabel(1));
|
label.setLayoutData(gridDataForLabel(1));
|
||||||
|
|
||||||
Button checkButton = getLinkCheckButtonControl(parent);
|
//Button checkButton = getLinkCheckButtonControl(parent);
|
||||||
|
|
||||||
Text text= getTextControl(parent);
|
Text text= getTextControl(parent);
|
||||||
text.setLayoutData(gridDataForText(1));
|
text.setLayoutData(gridDataForText(1));
|
||||||
|
@ -242,7 +242,7 @@ public class LinkToFileGroup extends StringButtonDialogField {
|
||||||
/**
|
/**
|
||||||
* Opens a file or directory browser depending on the link type.
|
* Opens a file or directory browser depending on the link type.
|
||||||
*/
|
*/
|
||||||
private void handleLinkTargetBrowseButtonPressed() {
|
protected void handleLinkTargetBrowseButtonPressed() {
|
||||||
String linkTargetName = linkTargetField.getText();
|
String linkTargetName = linkTargetField.getText();
|
||||||
File file = null;
|
File file = null;
|
||||||
String selection = null;
|
String selection = null;
|
||||||
|
@ -279,7 +279,7 @@ public class LinkToFileGroup extends StringButtonDialogField {
|
||||||
/**
|
/**
|
||||||
* Opens a path variable selection dialog
|
* Opens a path variable selection dialog
|
||||||
*/
|
*/
|
||||||
private void handleVariablesButtonPressed() {
|
protected void handleVariablesButtonPressed() {
|
||||||
int variableTypes = IResource.FOLDER;
|
int variableTypes = IResource.FOLDER;
|
||||||
|
|
||||||
// allow selecting file and folder variables when creating a
|
// allow selecting file and folder variables when creating a
|
||||||
|
@ -300,7 +300,7 @@ public class LinkToFileGroup extends StringButtonDialogField {
|
||||||
* a variable, if the value is a relative path.
|
* a variable, if the value is a relative path.
|
||||||
* Displays the resolved value if the entered value is a variable.
|
* Displays the resolved value if the entered value is a variable.
|
||||||
*/
|
*/
|
||||||
private void resolveVariable() {
|
protected void resolveVariable() {
|
||||||
if(!linkTargetField.isEnabled())
|
if(!linkTargetField.isEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -59,9 +59,9 @@ import org.eclipse.cdt.internal.ui.util.TableLayoutComposite;
|
||||||
public class ListDialogField extends DialogField {
|
public class ListDialogField extends DialogField {
|
||||||
|
|
||||||
public static class ColumnsDescription {
|
public static class ColumnsDescription {
|
||||||
private ColumnLayoutData[] columns;
|
protected ColumnLayoutData[] columns;
|
||||||
private String[] headers;
|
protected String[] headers;
|
||||||
private boolean drawLines;
|
protected boolean drawLines;
|
||||||
|
|
||||||
public ColumnsDescription(ColumnLayoutData[] columns, String[] headers, boolean drawLines) {
|
public ColumnsDescription(ColumnLayoutData[] columns, String[] headers, boolean drawLines) {
|
||||||
this.columns= columns;
|
this.columns= columns;
|
||||||
|
@ -103,7 +103,7 @@ public class ListDialogField extends DialogField {
|
||||||
|
|
||||||
private Label fLastSeparator;
|
private Label fLastSeparator;
|
||||||
|
|
||||||
private Control fTableControl;
|
protected Control fTableControl;
|
||||||
private Composite fButtonsControl;
|
private Composite fButtonsControl;
|
||||||
private ISelection fSelectionWhenEnabled;
|
private ISelection fSelectionWhenEnabled;
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ public class ListDialogField extends DialogField {
|
||||||
|
|
||||||
private Object fParentElement;
|
private Object fParentElement;
|
||||||
|
|
||||||
private ColumnsDescription fTableColumns;
|
protected ColumnsDescription fTableColumns;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -438,7 +438,7 @@ public class ListDialogField extends DialogField {
|
||||||
return fButtonsControl;
|
return fButtonsControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doButtonSelected(SelectionEvent e) {
|
protected void doButtonSelected(SelectionEvent e) {
|
||||||
if (fButtonControls != null) {
|
if (fButtonControls != null) {
|
||||||
for (int i= 0; i < fButtonControls.length; i++) {
|
for (int i= 0; i < fButtonControls.length; i++) {
|
||||||
if (e.widget == fButtonControls[i]) {
|
if (e.widget == fButtonControls[i]) {
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class SelectionButtonDialogField extends DialogField {
|
||||||
return fButton;
|
return fButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doWidgetSelected(SelectionEvent e) {
|
protected void doWidgetSelected(SelectionEvent e) {
|
||||||
if (isOkToUse(fButton)) {
|
if (isOkToUse(fButton)) {
|
||||||
changeValue(fButton.getSelection());
|
changeValue(fButton.getSelection());
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class SelectionButtonDialogFieldGroup extends DialogField {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doWidgetSelected(SelectionEvent e) {
|
protected void doWidgetSelected(SelectionEvent e) {
|
||||||
Button button= (Button)e.widget;
|
Button button= (Button)e.widget;
|
||||||
for (int i= 0; i < fButtons.length; i++) {
|
for (int i= 0; i < fButtons.length; i++) {
|
||||||
if (fButtons[i] == button) {
|
if (fButtons[i] == button) {
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class StringDialogField extends DialogField {
|
||||||
return fTextControl;
|
return fTextControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doModifyText(ModifyEvent e) {
|
protected void doModifyText(ModifyEvent e) {
|
||||||
if (isOkToUse(fTextControl)) {
|
if (isOkToUse(fTextControl)) {
|
||||||
fText= fTextControl.getText();
|
fText= fTextControl.getText();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue