mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Bug 567966 - CDT code clean up: type safety warnings
Generalize the type of elements and resolve type safety warnings Change-Id: I5cb8d06a80207a7df8240f499936cdc49d49964c Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
6ca0bb78bb
commit
87dff3db99
2 changed files with 35 additions and 34 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: %pluginName
|
Bundle-Name: %pluginName
|
||||||
Bundle-SymbolicName: org.eclipse.cdt.debug.ui; singleton:=true
|
Bundle-SymbolicName: org.eclipse.cdt.debug.ui; singleton:=true
|
||||||
Bundle-Version: 8.4.0.qualifier
|
Bundle-Version: 8.4.100.qualifier
|
||||||
Bundle-Activator: org.eclipse.cdt.debug.ui.CDebugUIPlugin
|
Bundle-Activator: org.eclipse.cdt.debug.ui.CDebugUIPlugin
|
||||||
Bundle-Vendor: %providerName
|
Bundle-Vendor: %providerName
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005, 2018 IBM Corporation and others.
|
* Copyright (c) 2005, 2020 IBM Corporation and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
|
* Alexander Fedorov (ArSysOp) - Bug 567966
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.debug.internal.ui.dialogfields;
|
package org.eclipse.cdt.debug.internal.ui.dialogfields;
|
||||||
|
|
||||||
|
@ -45,15 +46,16 @@ import org.eclipse.swt.widgets.Table;
|
||||||
/**
|
/**
|
||||||
* A list with a button bar.
|
* A list with a button bar.
|
||||||
* Typical buttons are 'Add', 'Remove', 'Up' and 'Down'.
|
* Typical buttons are 'Add', 'Remove', 'Up' and 'Down'.
|
||||||
* List model is independend of widget creation.
|
* List model is independent of widget creation.
|
||||||
* DialogFields controls are: Label, List and Composite containing buttons.
|
* DialogFields controls are: Label, List and Composite containing buttons.
|
||||||
*/
|
*/
|
||||||
public class ListDialogField extends DialogField {
|
//FIXME: Mostly duplicates org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField
|
||||||
|
public class ListDialogField<T> extends DialogField {
|
||||||
|
|
||||||
protected TableViewer fTable;
|
protected TableViewer fTable;
|
||||||
protected ILabelProvider fLabelProvider;
|
protected ILabelProvider fLabelProvider;
|
||||||
protected ListViewerAdapter fListViewerAdapter;
|
protected ListViewerAdapter fListViewerAdapter;
|
||||||
protected List fElements;
|
protected List<T> fElements;
|
||||||
protected ViewerComparator fViewerComparator;
|
protected ViewerComparator fViewerComparator;
|
||||||
|
|
||||||
protected String[] fButtonLabels;
|
protected String[] fButtonLabels;
|
||||||
|
@ -90,7 +92,7 @@ public class ListDialogField extends DialogField {
|
||||||
fListViewerAdapter = new ListViewerAdapter();
|
fListViewerAdapter = new ListViewerAdapter();
|
||||||
fParentElement = this;
|
fParentElement = this;
|
||||||
|
|
||||||
fElements = new ArrayList(10);
|
fElements = new ArrayList<>(10);
|
||||||
|
|
||||||
fButtonLabels = buttonLabels;
|
fButtonLabels = buttonLabels;
|
||||||
if (fButtonLabels != null) {
|
if (fButtonLabels != null) {
|
||||||
|
@ -442,8 +444,8 @@ public class ListDialogField extends DialogField {
|
||||||
/**
|
/**
|
||||||
* Sets the elements shown in the list.
|
* Sets the elements shown in the list.
|
||||||
*/
|
*/
|
||||||
public void setElements(List elements) {
|
public void setElements(List<? extends T> elements) {
|
||||||
fElements = new ArrayList(elements);
|
fElements = new ArrayList<>(elements);
|
||||||
if (fTable != null) {
|
if (fTable != null) {
|
||||||
fTable.refresh();
|
fTable.refresh();
|
||||||
}
|
}
|
||||||
|
@ -454,8 +456,8 @@ public class ListDialogField extends DialogField {
|
||||||
* Gets the elements shown in the list.
|
* Gets the elements shown in the list.
|
||||||
* The list returned is a copy, so it can be modified by the user.
|
* The list returned is a copy, so it can be modified by the user.
|
||||||
*/
|
*/
|
||||||
public List getElements() {
|
public List<? extends Object> getElements() {
|
||||||
return new ArrayList(fElements);
|
return new ArrayList<>(fElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -468,7 +470,7 @@ public class ListDialogField extends DialogField {
|
||||||
/**
|
/**
|
||||||
* Replace an element.
|
* Replace an element.
|
||||||
*/
|
*/
|
||||||
public void replaceElement(Object oldElement, Object newElement) throws IllegalArgumentException {
|
public void replaceElement(T oldElement, T newElement) throws IllegalArgumentException {
|
||||||
int idx = fElements.indexOf(oldElement);
|
int idx = fElements.indexOf(oldElement);
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
if (oldElement.equals(newElement) || fElements.contains(newElement)) {
|
if (oldElement.equals(newElement) || fElements.contains(newElement)) {
|
||||||
|
@ -476,7 +478,7 @@ public class ListDialogField extends DialogField {
|
||||||
}
|
}
|
||||||
fElements.set(idx, newElement);
|
fElements.set(idx, newElement);
|
||||||
if (fTable != null) {
|
if (fTable != null) {
|
||||||
List selected = getSelectedElements();
|
List<T> selected = getSelectedElements();
|
||||||
if (selected.remove(oldElement)) {
|
if (selected.remove(oldElement)) {
|
||||||
selected.add(newElement);
|
selected.add(newElement);
|
||||||
}
|
}
|
||||||
|
@ -492,7 +494,7 @@ public class ListDialogField extends DialogField {
|
||||||
/**
|
/**
|
||||||
* Adds an element at the end of the list.
|
* Adds an element at the end of the list.
|
||||||
*/
|
*/
|
||||||
public void addElement(Object element) {
|
public void addElement(T element) {
|
||||||
if (fElements.contains(element)) {
|
if (fElements.contains(element)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -506,15 +508,15 @@ public class ListDialogField extends DialogField {
|
||||||
/**
|
/**
|
||||||
* Adds elements at the end of the list.
|
* Adds elements at the end of the list.
|
||||||
*/
|
*/
|
||||||
public void addElements(List elements) {
|
public void addElements(List<? extends T> elements) {
|
||||||
int nElements = elements.size();
|
int nElements = elements.size();
|
||||||
|
|
||||||
if (nElements > 0) {
|
if (nElements > 0) {
|
||||||
// filter duplicated
|
// filter duplicated
|
||||||
ArrayList elementsToAdd = new ArrayList(nElements);
|
ArrayList<T> elementsToAdd = new ArrayList<>(nElements);
|
||||||
|
|
||||||
for (int i = 0; i < nElements; i++) {
|
for (int i = 0; i < nElements; i++) {
|
||||||
Object elem = elements.get(i);
|
T elem = elements.get(i);
|
||||||
if (!fElements.contains(elem)) {
|
if (!fElements.contains(elem)) {
|
||||||
elementsToAdd.add(elem);
|
elementsToAdd.add(elem);
|
||||||
}
|
}
|
||||||
|
@ -530,7 +532,7 @@ public class ListDialogField extends DialogField {
|
||||||
/**
|
/**
|
||||||
* Adds an element at a position.
|
* Adds an element at a position.
|
||||||
*/
|
*/
|
||||||
public void insertElementAt(Object element, int index) {
|
public void insertElementAt(T element, int index) {
|
||||||
if (fElements.contains(element)) {
|
if (fElements.contains(element)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -572,7 +574,7 @@ public class ListDialogField extends DialogField {
|
||||||
/**
|
/**
|
||||||
* Removes elements from the list.
|
* Removes elements from the list.
|
||||||
*/
|
*/
|
||||||
public void removeElements(List elements) {
|
public void removeElements(List<? extends Object> elements) {
|
||||||
if (elements.size() > 0) {
|
if (elements.size() > 0) {
|
||||||
fElements.removeAll(elements);
|
fElements.removeAll(elements);
|
||||||
if (fTable != null) {
|
if (fTable != null) {
|
||||||
|
@ -634,12 +636,12 @@ public class ListDialogField extends DialogField {
|
||||||
|
|
||||||
// ------- list maintenance
|
// ------- list maintenance
|
||||||
|
|
||||||
private List moveUp(List elements, List move) {
|
private List<T> moveUp(List<? extends T> elements, List<? extends T> move) {
|
||||||
int nElements = elements.size();
|
int nElements = elements.size();
|
||||||
List res = new ArrayList(nElements);
|
List<T> res = new ArrayList<>(nElements);
|
||||||
Object floating = null;
|
T floating = null;
|
||||||
for (int i = 0; i < nElements; i++) {
|
for (int i = 0; i < nElements; i++) {
|
||||||
Object curr = elements.get(i);
|
T curr = elements.get(i);
|
||||||
if (move.contains(curr)) {
|
if (move.contains(curr)) {
|
||||||
res.add(curr);
|
res.add(curr);
|
||||||
} else {
|
} else {
|
||||||
|
@ -655,22 +657,22 @@ public class ListDialogField extends DialogField {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveUp(List toMoveUp) {
|
private void moveUp(List<? extends T> toMoveUp) {
|
||||||
if (toMoveUp.size() > 0) {
|
if (toMoveUp.size() > 0) {
|
||||||
setElements(moveUp(fElements, toMoveUp));
|
setElements(moveUp(fElements, toMoveUp));
|
||||||
fTable.reveal(toMoveUp.get(0));
|
fTable.reveal(toMoveUp.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveDown(List toMoveDown) {
|
private void moveDown(List<? extends T> toMoveDown) {
|
||||||
if (toMoveDown.size() > 0) {
|
if (toMoveDown.size() > 0) {
|
||||||
setElements(reverse(moveUp(reverse(fElements), toMoveDown)));
|
setElements(reverse(moveUp(reverse(fElements), toMoveDown)));
|
||||||
fTable.reveal(toMoveDown.get(toMoveDown.size() - 1));
|
fTable.reveal(toMoveDown.get(toMoveDown.size() - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List reverse(List p) {
|
private List<T> reverse(List<? extends T> p) {
|
||||||
List reverse = new ArrayList(p.size());
|
List<T> reverse = new ArrayList<>(p.size());
|
||||||
for (int i = p.size() - 1; i >= 0; i--) {
|
for (int i = p.size() - 1; i >= 0; i--) {
|
||||||
reverse.add(p.get(i));
|
reverse.add(p.get(i));
|
||||||
}
|
}
|
||||||
|
@ -717,15 +719,14 @@ public class ListDialogField extends DialogField {
|
||||||
/**
|
/**
|
||||||
* Returns the selected elements.
|
* Returns the selected elements.
|
||||||
*/
|
*/
|
||||||
public List getSelectedElements() {
|
public List<T> getSelectedElements() {
|
||||||
List result = new ArrayList();
|
List<T> result = new ArrayList<>();
|
||||||
if (fTable != null) {
|
if (fTable != null) {
|
||||||
ISelection selection = fTable.getSelection();
|
IStructuredSelection selection = fTable.getStructuredSelection();
|
||||||
if (selection instanceof IStructuredSelection) {
|
@SuppressWarnings("unchecked")
|
||||||
Iterator iter = ((IStructuredSelection) selection).iterator();
|
Iterator<T> iter = selection.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
result.add(iter.next());
|
result.add(iter.next());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue