null
if none
* (before creation or after disposal).
*/
private List list;
private ArrayList channels;
/**
* The button box containing the Add, Remove, Up, and Down buttons;
* null
if none (before creation or after disposal).
*/
private Composite buttonBox;
/**
* The Add button.
*/
private Button addButton;
/**
* The Search button.
*/
private Button searchButton;
/**
* The Remove button.
*/
private Button removeButton;
/**
* The Up button.
*/
private Button upButton;
/**
* The Down button.
*/
private Button downButton;
/**
* The selection listener.
*/
private SelectionListener selectionListener;
/**
* Notifies that the Add button has been pressed.
*/
private void addPressed() {
setPresentsDefaultValue(false);
Channel input = getNewInputChannel();
if (input != null) {
int index = list.getSelectionIndex();
if (index >= 0) {
list.add(input.getTitle(), index + 1);
channels.add(index + 1, input);
} else {
list.add(input.getTitle(), 0);
channels.add(0, input);
}
selectionChanged();
}
}
/**
* Notifies that the Search button has been pressed.
*/
private void searchPressed() {
setPresentsDefaultValue(false);
SearchDialog sd = new SearchDialog(SiteListEditor.this
.getShell());
sd.open();
Channel[] inputs = sd.getChannels();
for(int i=0; i* This method is internal to the framework; subclassers should not call * this method. *
* * @return the shell */ protected Shell getShell() { if (addButton == null) return null; return addButton.getShell(); } /** * Notifies that the Remove button has been pressed. */ private void removePressed() { setPresentsDefaultValue(false); int index = list.getSelectionIndex(); if (index >= 0) { list.remove(index); channels.remove(index); selectionChanged(); } } /** * Notifies that the list selection has changed. */ private void selectionChanged() { int index = list.getSelectionIndex(); int size = list.getItemCount(); removeButton.setEnabled(index >= 0); upButton.setEnabled(size > 1 && index > 0); downButton.setEnabled(size > 1 && index >= 0 && index < size - 1); } /* (non-Javadoc) * Method declared on FieldEditor. */ public void setFocus() { if (list != null) { list.setFocus(); } } /** * Moves the currently selected item up or down. * * @param uptrue
if the item should move up,
* and false
if it should move down
*/
private void swap(boolean up) {
setPresentsDefaultValue(false);
int index = list.getSelectionIndex();
int target = up ? index - 1 : index + 1;
if (index >= 0) {
//list widget
String[] selection = list.getSelection();
Assert.isTrue(selection.length == 1);
list.remove(index);
list.add(selection[0], target);
list.setSelection(target);
//channels arrayList
Object obj = channels.remove(index);
channels.add(target, obj);
}
selectionChanged();
}
/**
* Notifies that the Up button has been pressed.
*/
private void upPressed() {
swap(true);
}
/*
* @see FieldEditor.setEnabled(boolean,Composite).
*/
public void setEnabled(boolean enabled, Composite parent) {
super.setEnabled(enabled, parent);
getListControl(parent).setEnabled(enabled);
addButton.setEnabled(enabled);
removeButton.setEnabled(enabled);
upButton.setEnabled(enabled);
downButton.setEnabled(enabled);
}
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
/**
* Creates a site list field editor.
*
* @param name the name of the preference this field editor works on
* @param labelText the label text of the field editor
* @param parent the parent of the field editor's control
*/
protected SiteListEditor(String name, String labelText, Composite parent) {
init(name, labelText);
createControl(parent);
}
/**
* Creates and returns a new item for the list.
*
* @return a new item
*/
protected Channel getNewInputChannel() {
InputDialog dialog;
dialog = new InputDialog(this.getShell(), "All The News",
"Enter new site name", "", null);
dialog.open();
if ("".equals(dialog.getValue()) || dialog.getValue() == null)
return null;
String title = dialog.getValue();
dialog = new InputDialog(this.getShell(), "All The News",
"Enter new site URL", "", null);
dialog.open();
if ("".equals(dialog.getValue()) || dialog.getValue() == null)
return null;
String url = dialog.getValue();
return new Channel(title, url);
}
}