/* (non-Javadoc)
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
NamedFilter flt = (NamedFilter) element;
return flt.getName();
}
});
namedFiltersViewer.setInput(namedFilters.toArray());
namedFiltersViewer.setComparator(new ViewerComparator());
namedFiltersViewer.addSelectionChangedListener(new ISelectionChangedListener() {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
*/
@Override
public void selectionChanged(SelectionChangedEvent e) {
IStructuredSelection sel = (IStructuredSelection) e.getSelection();
NamedFilter flt = (NamedFilter) sel.getFirstElement();
if (flt != null) {
// Delete button is only enabled when a fresh filter is selected
deleteButton.setEnabled(true);
clearContents();
// Set restrictions to load
restrictions = new ArrayList<ARestriction<?>>(flt.getRestrictions());
updateContents(false);
}
}
});
namedFiltersViewer.getCombo().addModifyListener(new ModifyListener() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
@Override
public void modifyText(ModifyEvent e) {
updateSaveButton();
// Delete button is being disabled as soon as the text is modified
deleteButton.setEnabled(false);
try {
save();
} catch (CoreException ce) {
// Log and show error
UIPlugin.logAndShowError(ce, true);
}
}
});
saveButton = new Button(group, SWT.NONE);
saveButton.setText(Messages.FilterSettingsDialog_label_save);
saveButton.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
NamedFilter flt = doFindNamedFilter();
if (flt != null) {
if (MessageDialog.openQuestion(getShell(),
Messages.FilterSettingsDialog_confirm_title,
Messages.FilterSettingsDialog_confirm_question)) {
// Remove old
namedFilters.remove(flt);
} else {
// Abort saving
return;
}
}
flt = new NamedFilter();
flt.setName(namedFiltersViewer.getCombo().getText().trim());
flt.setRestrictions(doGetRestrictions());
namedFilters.add(flt);
namedFiltersViewer.setInput(namedFilters.toArray());
try {
save();
} catch (CoreException ce) {
// Log and show error
UIPlugin.logAndShowError(ce, true);
}
}
});
deleteButton = new Button(group, SWT.NONE);
deleteButton.setText(Messages.FilterSettingsDialog_label_delete);
deleteButton.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
NamedFilter flt = doFindNamedFilter();
namedFilters.remove(flt);
namedFiltersViewer.setInput(namedFilters.toArray());
}
});
deleteButton.setEnabled(false);